From e0af859d27ba563e3b01037cbb88689f036d9333 Mon Sep 17 00:00:00 2001 From: Kevin Glowacz Date: Wed, 30 Apr 2008 10:08:11 -0500 Subject: [PATCH] Fix for labels that have a bracketed name and an index --- actionpack/lib/action_view/helpers/form_helper.rb | 2 ++ actionpack/test/template/form_helper_test.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 0 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index aa6247d..28ab777 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -467,8 +467,10 @@ module ActionView end def to_label_tag(text = nil, options = {}) + options = options.stringify_keys name_and_id = options.dup add_default_name_and_id(name_and_id) + options.delete("index") if options.has_key?("index") options["for"] = name_and_id["id"] content = (text.blank? ? nil : text.to_s) || method_name.humanize content_tag("label", content, options) diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index a6afa04..9fd2549 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -547,6 +547,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 "" + + "", + _erbout + end + def test_form_builder_does_not_have_form_for_method assert ! ActionView::Helpers::FormBuilder.instance_methods.include?('form_for') end -- 1.5.5.1