From 81a6761af2b20183c78853caa4daea4ccf6b4cb7 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Tue, 21 Feb 2017 08:49:15 +0000 Subject: Support mapping of non-model classes --- .../lib/action_dispatch/routing/polymorphic_routes.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb index 512e23c833..1c44d25ef6 100644 --- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb +++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb @@ -165,8 +165,11 @@ module ActionDispatch end def polymorphic_mapping(record) - return false unless record.respond_to?(:to_model) - _routes.polymorphic_mappings[record.to_model.model_name.name] + if record.respond_to?(:to_model) + _routes.polymorphic_mappings[record.to_model.model_name.name] + else + _routes.polymorphic_mappings[record.class.name] + end end class HelperMethodBuilder # :nodoc: @@ -321,7 +324,11 @@ module ActionDispatch private def polymorphic_mapping(target, record) - target._routes.polymorphic_mappings[record.to_model.model_name.name] + if record.respond_to?(:to_model) + target._routes.polymorphic_mappings[record.to_model.model_name.name] + else + target._routes.polymorphic_mappings[record.class.name] + end end def get_method_for_class(klass) -- cgit v1.2.3