From c1e74f3aeb11e1f042acd7a722f1209eaf7bc4e9 Mon Sep 17 00:00:00 2001
From: chris finne
Date: Sun, 22 Feb 2009 11:36:32 -0800
Subject: [PATCH] html_options_for_extra_tag_in_form config for ActionView::Base
---
actionpack/lib/action_view/base.rb | 10 ++++++++++
.../lib/action_view/helpers/form_tag_helper.rb | 4 ++--
.../test/template/active_record_helper_test.rb | 16 ++++++++++++++++
3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 65b2062..bbf60a2 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -182,6 +182,16 @@ module ActionView #:nodoc:
# that alert()s the caught exception (and then re-raises it).
cattr_accessor :debug_rjs
+ ##
+ # :singleton-method:
+ # Specifies the html options for the extra div tag added to forms that wraps
+ # the hidden input fields for _method and authenticity_token.
+ # To add a dom class to this, try: html_options_for_extra_tag_in_form={:class=>'hideMe'}
+ # To remove or change the default setting which is {:style => 'margin:0;padding:0'}
+ # try html_options_for_extra_tag_in_form={:style=>'display:none'}
+ cattr_accessor :html_options_for_extra_tag_in_form
+ @@html_options_for_extra_tag_in_form = {:style => 'margin:0;padding:0'}
+
# Specify whether templates should be cached. Otherwise the file we be read everytime it is accessed.
# Automaticaly reloading templates are not thread safe and should only be used in development mode.
@@cache_template_loading = false
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index 4646bc1..bd9d4a4 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -444,10 +444,10 @@ module ActionView
''
when /^post$/i, "", nil
html_options["method"] = "post"
- protect_against_forgery? ? content_tag(:div, token_tag, :style => 'margin:0;padding:0') : ''
+ protect_against_forgery? ? content_tag(:div, token_tag, Base.html_options_for_extra_tag_in_form) : ''
else
html_options["method"] = "post"
- content_tag(:div, tag(:input, :type => "hidden", :name => "_method", :value => method) + token_tag, :style => 'margin:0;padding:0')
+ content_tag(:div, tag(:input, :type => "hidden", :name => "_method", :value => method) + token_tag, Base.html_options_for_extra_tag_in_form)
end
end
diff --git a/actionpack/test/template/active_record_helper_test.rb b/actionpack/test/template/active_record_helper_test.rb
index e46f95d..061cd86 100644
--- a/actionpack/test/template/active_record_helper_test.rb
+++ b/actionpack/test/template/active_record_helper_test.rb
@@ -151,6 +151,22 @@ class ActiveRecordHelperTest < ActionView::TestCase
)
end
+ def test_form_with_protect_against_forgery_and_html_options_for_extra_tag_in_form
+ @protect_against_forgery = true
+ @request_forgery_protection_token = 'authenticity_token'
+ @form_authenticity_token = '123'
+ ActionView::Base.html_options_for_extra_tag_in_form.merge!(:class=>'hideMe')
+ assert_dom_equal(
+ %(
),
+ form("post")
+ )
+ ActionView::Base.html_options_for_extra_tag_in_form.merge!(:class=>'hideMe', :style=>nil)
+ assert_dom_equal(
+ %(),
+ form("post")
+ )
+ end
+
def test_form_with_method_option
assert_dom_equal(
%(),
--
1.6.0
From c0f26892ff33f069c6eb56fb90c9c26a2e9c2a5e Mon Sep 17 00:00:00 2001
From: chris finne
Date: Wed, 25 Feb 2009 06:05:06 -0800
Subject: [PATCH] fix comment
---
actionpack/lib/action_view/base.rb | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index bbf60a2..3af884a 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -186,9 +186,8 @@ module ActionView #:nodoc:
# :singleton-method:
# Specifies the html options for the extra div tag added to forms that wraps
# the hidden input fields for _method and authenticity_token.
- # To add a dom class to this, try: html_options_for_extra_tag_in_form.merge!(:class=>'hideMe')
- # To remove or change the default setting which is {:style => 'margin:0;padding:0'}
- # try html_options_for_extra_tag_in_form.merge!(:style=>'display:none')
+ # To use a dom class, try: html_options_for_extra_tag_in_form={:class=>'hideMe'}
+ # Or try html_options_for_extra_tag_in_form={:style=>'display:none', :class=>'hideMe'}
cattr_accessor :html_options_for_extra_tag_in_form
@@html_options_for_extra_tag_in_form = {:style => 'margin:0;padding:0'}
--
1.6.0