diff options
author | Bert Goethals <bert@bertg.be> | 2012-08-08 22:40:06 +0200 |
---|---|---|
committer | Bert Goethals <bert@bertg.be> | 2012-08-08 22:40:06 +0200 |
commit | 920d9ee4d845c87c016acd660cb4a71e03a7207d (patch) | |
tree | 98be0a5fed7ed362762cf53fef4c1e4ed01d8dfa | |
parent | 4154bf012d2bec2aae79e4a49aa94a70d3e91d49 (diff) | |
download | rails-920d9ee4d845c87c016acd660cb4a71e03a7207d.tar.gz rails-920d9ee4d845c87c016acd660cb4a71e03a7207d.tar.bz2 rails-920d9ee4d845c87c016acd660cb4a71e03a7207d.zip |
Naming helpers should first check if passed object responds to model_name
-rw-r--r-- | activemodel/lib/active_model/naming.rb | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/activemodel/lib/active_model/naming.rb b/activemodel/lib/active_model/naming.rb index 7ba439fb3e..2102282c02 100644 --- a/activemodel/lib/active_model/naming.rb +++ b/activemodel/lib/active_model/naming.rb @@ -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 |