aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb1
-rw-r--r--actionpack/test/template/form_helper_test.rb12
2 files changed, 13 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index 829f84dd64..4459ccbce5 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -471,6 +471,7 @@ module ActionView
options = options.stringify_keys
name_and_id = options.dup
add_default_name_and_id(name_and_id)
+ options.delete("index")
options["for"] ||= name_and_id["id"]
content = (text.blank? ? nil : text.to_s) || method_name.humanize
label_tag(name_and_id["id"], content, options)
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 87e6ca12a1..b4857fcb62 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -540,6 +540,18 @@ class FormHelperTest < ActionView::TestCase
_erbout
end
+ def test_fields_for_object_with_bracketed_name_and_index
+ _erbout = ''
+ fields_for("author[post]", @post, :index => 1) do |f|
+ _erbout.concat f.label(:title)
+ _erbout.concat f.text_field(:title)
+ end
+
+ assert_dom_equal "<label for=\"author_post_1_title\">Title</label>" +
+ "<input name='author[post][1][title]' size='30' type='text' id='author_post_1_title' value='Hello World' />",
+ _erbout
+ end
+
def test_form_builder_does_not_have_form_for_method
assert ! ActionView::Helpers::FormBuilder.instance_methods.include?('form_for')
end