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
This commit is contained in:
parent
d761ac4095
commit
d5a93b6241
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 = ""
|
||||
|
|
Loading…
Reference in New Issue