Permalink
Browse files

Merge pull request #5144 from nashby/input-name-nil

correct fetching :name option in form fields
  • Loading branch information...
2 parents 335fac5 + f0a5d32 commit e04fa0e58976b452fcb1fe114777154c3abb4799 @tenderlove tenderlove committed Feb 24, 2012
Showing with 8 additions and 3 deletions.
  1. +3 −3 actionpack/lib/action_view/helpers/tags/base.rb
  2. +5 −0 actionpack/test/template/form_helper_test.rb
View
6 actionpack/lib/action_view/helpers/tags/base.rb
@@ -75,14 +75,14 @@ def add_default_name_and_id_for_value(tag_value, options)
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
View
5 actionpack/test/template/form_helper_test.rb
@@ -305,6 +305,11 @@ def test_text_field_with_nil_value
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" />'

0 comments on commit e04fa0e

Please sign in to comment.