mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #7293 from Bertg/activemodel_naming_helpers_try_model_name_first
Naming helpers should first check if passed object responds to model_name
This commit is contained in:
commit
2da242f63c
1 changed files with 3 additions and 5 deletions
|
@ -300,11 +300,9 @@ module ActiveModel
|
|||
|
||||
private
|
||||
def self.model_name_from_record_or_class(record_or_class)
|
||||
(record_or_class.is_a?(Class) ? record_or_class : convert_to_model(record_or_class).class).model_name
|
||||
end
|
||||
|
||||
def self.convert_to_model(object)
|
||||
object.respond_to?(:to_model) ? object.to_model : object
|
||||
return record_or_class.model_name if record_or_class.respond_to?(:model_name)
|
||||
return record_or_class.to_model.class.model_name if record_or_class.respond_to?(:to_model)
|
||||
record_or_class.class.model_name
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue