From 1cbe917237c3f8e6bdcbe97835b26b55354b8566 Mon Sep 17 00:00:00 2001 From: David Lee Date: Sun, 8 May 2011 04:40:47 -0700 Subject: There are no snowmen here --- actionpack/lib/action_view/helpers/form_tag_helper.rb | 6 +++--- actionpack/test/template/form_helper_test.rb | 4 ++-- actionpack/test/template/form_tag_helper_test.rb | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index a91e86f4db..5c1a4ae483 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -611,8 +611,8 @@ module ActionView end def extra_tags_for_form(html_options) - snowman_tag = tag(:input, :type => "hidden", - :name => "utf8", :value => "✓".html_safe) + utf8_enforcer = 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 +629,7 @@ module ActionView tag(:input, :type => "hidden", :name => "_method", :value => method) + token_tag(authenticity_token) end - tags = snowman_tag << method_tag + tags = utf8_enforcer << method_tag content_tag(:div, tags, :style => 'margin:0;padding:0;display:inline') end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 5296556fe6..0507045ad2 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -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 = %{
} txt << %{} 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_text(action, id, html_class, remote, multipart, method) + hidden_fields(method) + contents + "" end def test_default_form_builder diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index f95308b847..979251bfd1 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -9,7 +9,7 @@ class FormTagHelperTest < ActionView::TestCase @controller = BasicController.new end - def snowman(options = {}) + def hidden_fields(options = {}) method = options[:method] txt = %{
} @@ -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 << "" -- cgit v1.2.3 From fa3fc520698092a002562107731b0d3b97e203d4 Mon Sep 17 00:00:00 2001 From: David Lee Date: Mon, 9 May 2011 16:16:55 -0700 Subject: Make utf8 enforcer param customizeable --- actionpack/lib/action_view/helpers/controller_helper.rb | 2 +- actionpack/lib/action_view/helpers/form_tag_helper.rb | 13 ++++++++++--- actionpack/lib/action_view/railtie.rb | 7 +++++++ railties/guides/source/configuring.textile | 4 +++- railties/test/application/configuration_test.rb | 15 +++++++++++++++ 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/actionpack/lib/action_view/helpers/controller_helper.rb b/actionpack/lib/action_view/helpers/controller_helper.rb index db59bca159..1a583e62ae 100644 --- a/actionpack/lib/action_view/helpers/controller_helper.rb +++ b/actionpack/lib/action_view/helpers/controller_helper.rb @@ -20,4 +20,4 @@ module ActionView end end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 5c1a4ae483..dcc96c0168 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -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 url_for_options just like # ActionController::Base#url_for. The method for the form defaults to POST. # @@ -611,8 +618,8 @@ module ActionView end def extra_tags_for_form(html_options) - utf8_enforcer = tag(:input, :type => "hidden", - :name => "utf8", :value => "✓".html_safe) + utf8_enforcer_tag = tag(:input, :type => "hidden", + :name => utf8_enforcer_param, :value => "✓".html_safe) authenticity_token = html_options.delete("authenticity_token") method = html_options.delete("method").to_s @@ -629,7 +636,7 @@ module ActionView tag(:input, :type => "hidden", :name => "_method", :value => method) + token_tag(authenticity_token) end - tags = utf8_enforcer << method_tag + tags = utf8_enforcer_tag << method_tag content_tag(:div, tags, :style => 'margin:0;padding:0;display:inline') end diff --git a/actionpack/lib/action_view/railtie.rb b/actionpack/lib/action_view/railtie.rb index 80391d72cc..b12aa4527b 100644 --- a/actionpack/lib/action_view/railtie.rb +++ b/actionpack/lib/action_view/railtie.rb @@ -8,6 +8,13 @@ module ActionView config.action_view.stylesheet_expansions = {} config.action_view.javascript_expansions = { :defaults => %w(jquery jquery_ujs) } + initializer "action_view.utf8_enforcer_param" do |app| + ActiveSupport.on_load(:action_view) do + param = app.config.action_view.delete(:utf8_enforcer_param) + ActionView::Helpers::FormTagHelper.utf8_enforcer_param = param + end + end + initializer "action_view.cache_asset_ids" do |app| unless app.config.cache_classes ActiveSupport.on_load(:action_view) do diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index a4cc62c117..923de8b7c0 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -330,7 +330,9 @@ And can reference in the view with the following code: <%= stylesheet_link_tag :special %> -* +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.utf8_enforcer_param+ tells Rails what the +name+ attribute should be for the hidden tag that's used for enforcing UTF8 encoding in form submissions. The default is +'utf8'+. + +* +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 diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 477dada820..5d47922ef5 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -250,6 +250,21 @@ module ApplicationTests assert last_response.body =~ /_xsrf_token_here/ end + test "utf8 enforcer param can be changed" do + make_basic_app do + app.config.action_view.utf8_enforcer_param = "_unicode" + end + + class ::OmgController < ActionController::Base + def index + render :inline => "<%= form_tag('/') %>" + end + end + + get "/" + assert last_response.body =~ /_unicode/ + end + test "config.action_controller.perform_caching = true" do make_basic_app do |app| app.config.action_controller.perform_caching = true -- cgit v1.2.3 From 91e3046b717117b4d2961b813fee674fdda2cb47 Mon Sep 17 00:00:00 2001 From: David Lee Date: Fri, 13 May 2011 17:54:29 -0700 Subject: Make utf8_enforcer_tag an overrideable method --- actionpack/lib/action_view/helpers/form_tag_helper.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index dcc96c0168..dd19fd2de9 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -604,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| @@ -618,9 +625,6 @@ module ActionView end def extra_tags_for_form(html_options) - utf8_enforcer_tag = tag(:input, :type => "hidden", - :name => utf8_enforcer_param, :value => "✓".html_safe) - authenticity_token = html_options.delete("authenticity_token") method = html_options.delete("method").to_s -- cgit v1.2.3 From 9b305983e3518093f3b393a254f296ca2be29968 Mon Sep 17 00:00:00 2001 From: David Lee Date: Fri, 20 May 2011 18:40:59 -0700 Subject: Remove utf8_enforcer_param config option --- actionpack/lib/action_view/railtie.rb | 7 ------- railties/guides/source/configuring.textile | 2 -- railties/test/application/configuration_test.rb | 15 --------------- 3 files changed, 24 deletions(-) diff --git a/actionpack/lib/action_view/railtie.rb b/actionpack/lib/action_view/railtie.rb index b12aa4527b..80391d72cc 100644 --- a/actionpack/lib/action_view/railtie.rb +++ b/actionpack/lib/action_view/railtie.rb @@ -8,13 +8,6 @@ module ActionView config.action_view.stylesheet_expansions = {} config.action_view.javascript_expansions = { :defaults => %w(jquery jquery_ujs) } - initializer "action_view.utf8_enforcer_param" do |app| - ActiveSupport.on_load(:action_view) do - param = app.config.action_view.delete(:utf8_enforcer_param) - ActionView::Helpers::FormTagHelper.utf8_enforcer_param = param - end - end - initializer "action_view.cache_asset_ids" do |app| unless app.config.cache_classes ActiveSupport.on_load(:action_view) do diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index 923de8b7c0..80de36070d 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -330,8 +330,6 @@ And can reference in the view with the following code: <%= stylesheet_link_tag :special %> -* +config.action_view.utf8_enforcer_param+ tells Rails what the +name+ attribute should be for the hidden tag that's used for enforcing UTF8 encoding in form submissions. The default is +'utf8'+. - * +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 diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 5d47922ef5..477dada820 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -250,21 +250,6 @@ module ApplicationTests assert last_response.body =~ /_xsrf_token_here/ end - test "utf8 enforcer param can be changed" do - make_basic_app do - app.config.action_view.utf8_enforcer_param = "_unicode" - end - - class ::OmgController < ActionController::Base - def index - render :inline => "<%= form_tag('/') %>" - end - end - - get "/" - assert last_response.body =~ /_unicode/ - end - test "config.action_controller.perform_caching = true" do make_basic_app do |app| app.config.action_controller.perform_caching = true -- cgit v1.2.3