Permalink
Browse files

Convert to model before calling model_name on a record in ActiveModel…

…::Naming

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
ernie authored and josevalim committed Oct 4, 2010
1 parent b7c49ce commit 33aaa15f6208d65ca043ffcc5dc161d410963e9d
Showing with 5 additions and 1 deletion.
  1. +5 −1 activemodel/lib/active_model/naming.rb
@@ -129,7 +129,11 @@ 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 : record_or_class.class).model_name
+ (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
end
end

0 comments on commit 33aaa15

Please sign in to comment.