diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-02-24 08:42:52 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-02-24 08:42:52 -0800 |
commit | e04fa0e58976b452fcb1fe114777154c3abb4799 (patch) | |
tree | 4e6201886cacf652728d2234cb2b479b3c143320 /actionpack | |
parent | 335fac56b671cd627ed55cbd41a62d3890342de4 (diff) | |
parent | f0a5d325375d9f453d4cc6c6bf555561e52d4ea7 (diff) | |
download | rails-e04fa0e58976b452fcb1fe114777154c3abb4799.tar.gz rails-e04fa0e58976b452fcb1fe114777154c3abb4799.tar.bz2 rails-e04fa0e58976b452fcb1fe114777154c3abb4799.zip |
Merge pull request #5144 from nashby/input-name-nil
correct fetching :name option in form fields
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/helpers/tags/base.rb | 6 | ||||
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 5 |
2 files changed, 8 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/tags/base.rb b/actionpack/lib/action_view/helpers/tags/base.rb index 1ece0ad2fc..d949ff5194 100644 --- a/actionpack/lib/action_view/helpers/tags/base.rb +++ b/actionpack/lib/action_view/helpers/tags/base.rb @@ -75,14 +75,14 @@ module ActionView def add_default_name_and_id(options) if options.has_key?("index") - options["name"] ||= tag_name_with_index(options["index"]) + options["name"] ||= options.fetch("name"){ tag_name_with_index(options["index"]) } options["id"] = options.fetch("id"){ tag_id_with_index(options["index"]) } options.delete("index") elsif defined?(@auto_index) - options["name"] ||= tag_name_with_index(@auto_index) + options["name"] ||= options.fetch("name"){ tag_name_with_index(@auto_index) } options["id"] = options.fetch("id"){ tag_id_with_index(@auto_index) } else - options["name"] ||= options['multiple'] ? tag_name_multiple : tag_name + options["name"] ||= options.fetch("name"){ options['multiple'] ? tag_name_multiple : tag_name } options["id"] = options.fetch("id"){ tag_id } end options["id"] = [options.delete('namespace'), options["id"]].compact.join("_").presence diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index e4cb7e02a0..61d728ce66 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -305,6 +305,11 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, text_field("post", "title", :value => nil) end + def test_text_field_with_nil_name + expected = '<input id="post_title" size="30" type="text" value="Hello World" />' + assert_dom_equal expected, text_field("post", "title", :name => nil) + end + def test_text_field_doesnt_change_param_values object_name = 'post[]' expected = '<input id="post_123_title" name="post[123][title]" size="30" type="text" value="Hello World" />' |