From f7b7d3c5950b0da4e50171a3e9cc40f5c5fed4ba Mon Sep 17 00:00:00 2001 From: Victor Costan Date: Sat, 15 May 2010 20:05:53 -0400 Subject: [PATCH] Factored out the code for the
wrapping hidden inputs at the beginning of a form. --- .../lib/action_view/helpers/form_tag_helper.rb | 13 +++++++++++-- actionpack/test/template/form_tag_helper_test.rb | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 2a3f826..a412f7c 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -524,6 +524,15 @@ module ActionView number_field_tag(name, value, options.stringify_keys.update("type" => "range")) end + # Creates a wrapper for hidden input fields. + # + # ==== Examples + # hidden_field_wrapper_tag hidden_field_tag('tags_list') + # =>
+ def hidden_field_wrapper_tag(contents) + content_tag(:div, contents, :style => 'margin:0;padding:0;display:inline') + end + private def html_options_for_form(url_for_options, options, *parameters_for_url) returning options.stringify_keys do |html_options| @@ -540,10 +549,10 @@ module ActionView '' when /^post$/i, "", nil html_options["method"] = "post" - protect_against_forgery? ? content_tag(:div, token_tag, :style => 'margin:0;padding:0;display:inline') : '' + protect_against_forgery? ? hidden_field_wrapper_tag(token_tag) : '' else html_options["method"] = "post" - content_tag(:div, tag(:input, :type => "hidden", :name => "_method", :value => method) + token_tag, :style => 'margin:0;padding:0;display:inline') + hidden_field_wrapper_tag(tag(:input, :type => "hidden", :name => "_method", :value => method) + token_tag) end end diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 1c095b6..bb701de 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -90,6 +90,12 @@ class FormTagHelperTest < ActionView::TestCase assert_match VALID_HTML_ID, input_elem['id'] end + def test_hidden_field_wrapper_tag + actual = hidden_field_wrapper_tag "contents" + expected = %(
contents
) + assert_dom_equal expected, actual + end + def test_file_field_tag assert_dom_equal "", file_field_tag("picsplz") end -- 1.7.0.4