Permalink
Browse files

Naming helpers should first check if passed object responds to model_…

…name
  • Loading branch information...
1 parent 4154bf0 commit 920d9ee4d845c87c016acd660cb4a71e03a7207d @Bertg Bertg committed Aug 8, 2012
Showing with 3 additions and 5 deletions.
  1. +3 −5 activemodel/lib/active_model/naming.rb
@@ -300,11 +300,9 @@ def self.param_key(record_or_class)
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

0 comments on commit 920d9ee

Please sign in to comment.