From d5a93b6241b4df64f9656853d386eca96b6f6baf Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Fri, 26 Oct 2007 04:48:19 +0000 Subject: FormHelper's auto_index should use #to_param instead of #id_before_type_cast. Closes #9994 [mattly] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8033 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 ++ actionpack/lib/action_view/helpers/form_helper.rb | 6 +++--- actionpack/test/template/form_helper_test.rb | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index ca1cf69d9a..406a7b75ac 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* FormHelper's auto_index should use #to_param instead of #id_before_type_cast. Closes #9994 [mattly] + * Doc typo fixes for ActiveRecordHelper. Closes #9973 [mikong] * Make example parameters in restful routing docs idiomatic. Closes #9993 [danger] diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index cc81bad2b4..1a3c842271 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -415,10 +415,10 @@ module ActionView @template_object, @local_binding = template_object, local_binding @object = object if @object_name.sub!(/\[\]$/,"") - if object ||= @template_object.instance_variable_get("@#{Regexp.last_match.pre_match}") and object.respond_to?(:id_before_type_cast) - @auto_index = object.id_before_type_cast + if object ||= @template_object.instance_variable_get("@#{Regexp.last_match.pre_match}") and object.respond_to?(:to_param) + @auto_index = object.to_param else - raise ArgumentError, "object[] naming but object param and @object var don't exist or don't respond to id_before_type_cast: #{object.inspect}" + raise ArgumentError, "object[] naming but object param and @object var don't exist or don't respond to to_param: #{object.inspect}" end end end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index d00bd16ad8..f37469954a 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -6,7 +6,7 @@ silence_warnings do alias_method :title_before_type_cast, :title unless respond_to?(:title_before_type_cast) alias_method :body_before_type_cast, :body unless respond_to?(:body_before_type_cast) alias_method :author_name_before_type_cast, :author_name unless respond_to?(:author_name_before_type_cast) - + def new_record=(boolean) @new_record = boolean end @@ -53,6 +53,7 @@ class FormHelperTest < Test::Unit::TestCase end def @post.id; 123; end def @post.id_before_type_cast; 123; end + def @post.to_param; '123'; end @post.title = "Hello World" @post.author_name = "" -- cgit v1.2.3