From 5851cce10848ea1fae2d106d03ae2bf9e271b59e Mon Sep 17 00:00:00 2001 From: Stephen Blackstone Date: Fri, 18 Sep 2009 10:52:22 -0400 Subject: [PATCH] Changed id creation for form tags when index specified --- actionpack/lib/action_view/helpers/form_helper.rb | 2 +- actionpack/test/template/form_helper_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 32b9c4a..66ad08b 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -292,7 +292,7 @@ module ActionView html_options = if object.respond_to?(:new_record?) && object.new_record? - { :class => dom_class(object, :new), :id => dom_id(object), :method => :post } + { :class => dom_class(object, :new), :id => dom_id(object) + (options[:index].nil? ? "" : "_#{options[:index]}"), :method => :post } else { :class => dom_class(object, :edit), :id => dom_id(object, :edit), :method => :put } end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index be15b06..59e38f1 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -1272,6 +1272,16 @@ class FormHelperTest < ActionView::TestCase assert_equal expected, output_buffer end + def test_form_for_with_index_on_new_objects + @post = Post.new + @post.new_record = true + def @post.id() nil end + form_for(@post, :index => 5) do |f| + end + expected = "
" + assert_dom_equal expected, output_buffer + end + def test_form_for_with_existing_object_in_list @post.new_record = false @comment.save -- 1.5.4.5