mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Merge pull request #549 from dlee/utf8_enforcer
Utf8 enforcer param customization
This commit is contained in:
@@ -20,4 +20,4 @@ module ActionView
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,6 +17,13 @@ module ActionView
|
||||
include UrlHelper
|
||||
include TextHelper
|
||||
|
||||
# You can change what the name will be for the hidden tag that forces utf8
|
||||
# encoding for forms generated with Rails form helpers.
|
||||
#
|
||||
# ActionView::Helpers::FormTagHelper.utf8_enforcer_param = "_unicode"
|
||||
mattr_accessor :utf8_enforcer_param
|
||||
@@utf8_enforcer_param = "utf8"
|
||||
|
||||
# Starts a form tag that points the action to an url configured with <tt>url_for_options</tt> just like
|
||||
# ActionController::Base#url_for. The method for the form defaults to POST.
|
||||
#
|
||||
@@ -597,6 +604,13 @@ module ActionView
|
||||
number_field_tag(name, value, options.stringify_keys.update("type" => "range"))
|
||||
end
|
||||
|
||||
# Creates the hidden UTF8 enforcer tag. Override this method in a helper
|
||||
# to customize the tag. If you just need to change the field name, set the
|
||||
# +config.action_view.utf8_enforcer_param+ configuration option instead.
|
||||
def utf8_enforcer_tag
|
||||
tag(:input, :type => "hidden", :name => utf8_enforcer_param, :value => "✓".html_safe)
|
||||
end
|
||||
|
||||
private
|
||||
def html_options_for_form(url_for_options, options, *parameters_for_url)
|
||||
options.stringify_keys.tap do |html_options|
|
||||
@@ -611,9 +625,6 @@ module ActionView
|
||||
end
|
||||
|
||||
def extra_tags_for_form(html_options)
|
||||
snowman_tag = tag(:input, :type => "hidden",
|
||||
:name => "utf8", :value => "✓".html_safe)
|
||||
|
||||
authenticity_token = html_options.delete("authenticity_token")
|
||||
method = html_options.delete("method").to_s
|
||||
|
||||
@@ -629,7 +640,7 @@ module ActionView
|
||||
tag(:input, :type => "hidden", :name => "_method", :value => method) + token_tag(authenticity_token)
|
||||
end
|
||||
|
||||
tags = snowman_tag << method_tag
|
||||
tags = utf8_enforcer_tag << method_tag
|
||||
content_tag(:div, tags, :style => 'margin:0;padding:0;display:inline')
|
||||
end
|
||||
|
||||
|
||||
@@ -1890,7 +1890,7 @@ class FormHelperTest < ActionView::TestCase
|
||||
assert_dom_equal expected, output_buffer
|
||||
end
|
||||
|
||||
def snowman(method = nil)
|
||||
def hidden_fields(method = nil)
|
||||
txt = %{<div style="margin:0;padding:0;display:inline">}
|
||||
txt << %{<input name="utf8" type="hidden" value="✓" />}
|
||||
if method && !method.to_s.in?(['get', 'post'])
|
||||
@@ -1918,7 +1918,7 @@ class FormHelperTest < ActionView::TestCase
|
||||
method = options
|
||||
end
|
||||
|
||||
form_text(action, id, html_class, remote, multipart, method) + snowman(method) + contents + "</form>"
|
||||
form_text(action, id, html_class, remote, multipart, method) + hidden_fields(method) + contents + "</form>"
|
||||
end
|
||||
|
||||
def test_default_form_builder
|
||||
|
||||
@@ -9,7 +9,7 @@ class FormTagHelperTest < ActionView::TestCase
|
||||
@controller = BasicController.new
|
||||
end
|
||||
|
||||
def snowman(options = {})
|
||||
def hidden_fields(options = {})
|
||||
method = options[:method]
|
||||
|
||||
txt = %{<div style="margin:0;padding:0;display:inline">}
|
||||
@@ -34,7 +34,7 @@ class FormTagHelperTest < ActionView::TestCase
|
||||
end
|
||||
|
||||
def whole_form(action = "http://www.example.com", options = {})
|
||||
out = form_text(action, options) + snowman(options)
|
||||
out = form_text(action, options) + hidden_fields(options)
|
||||
|
||||
if block_given?
|
||||
out << yield << "</form>"
|
||||
|
||||
@@ -330,7 +330,7 @@ And can reference in the view with the following code:
|
||||
<%= stylesheet_link_tag :special %>
|
||||
</ruby>
|
||||
|
||||
* +ActionView::Helpers::AssetTagHelper::AssetPaths.cache_asset_ids+ With the cache enabled, the asset tag helper methods will make fewer expensive file system calls (the default implementation checks the file system timestamp). However this prevents you from modifying any asset files while the server is running.
|
||||
* +config.action_view.cache_asset_ids+ With the cache enabled, the asset tag helper methods will make fewer expensive file system calls (the default implementation checks the file system timestamp). However this prevents you from modifying any asset files while the server is running.
|
||||
|
||||
h4. Configuring Action Mailer
|
||||
|
||||
|
||||
Reference in New Issue
Block a user