Permalink
Browse files

Make utf8 enforcer param customizeable

  • Loading branch information...
1 parent 1cbe917 commit fa3fc520698092a002562107731b0d3b97e203d4 @dlee dlee committed May 9, 2011
@@ -20,4 +20,4 @@ def assign_controller(controller)
end
end
end
-end
+end
@@ -17,6 +17,13 @@ module FormTagHelper
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.
#
@@ -611,8 +618,8 @@ def html_options_for_form(url_for_options, options, *parameters_for_url)
end
def extra_tags_for_form(html_options)
- utf8_enforcer = tag(:input, :type => "hidden",
- :name => "utf8", :value => "&#x2713;".html_safe)
+ utf8_enforcer_tag = tag(:input, :type => "hidden",
+ :name => utf8_enforcer_param, :value => "&#x2713;".html_safe)
authenticity_token = html_options.delete("authenticity_token")
method = html_options.delete("method").to_s
@@ -629,7 +636,7 @@ def extra_tags_for_form(html_options)
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
@@ -8,6 +8,13 @@ class Railtie < Rails::Railtie
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
@@ -330,7 +330,9 @@ 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.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
@@ -250,6 +250,21 @@ def index
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

0 comments on commit fa3fc52

Please sign in to comment.