From 34b2ded2ff632df8bbb3fe4a2ff1d9dbcbcba85b Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 6 May 2014 16:08:51 -0700 Subject: only test `persisted?` on the record once also avoid the case of calling `persisted?` on something that doesn't respond to it --- actionpack/lib/action_dispatch/routing/polymorphic_routes.rb | 10 +++++++--- 1 file changed, 7 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 70b1be3197..63c7799316 100644 --- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb +++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb @@ -132,7 +132,7 @@ module ActionDispatch record = record_or_hash_or_array end - if options[:action] == 'new' || record.try(:persisted?) + if options[:action] == 'new' inflection = lambda { |name| name.singular_route_key } else inflection = lambda { |name| name.route_key } @@ -160,8 +160,12 @@ module ActionDispatch when Class inflection.call record.model_name else - args << record.to_model if record.persisted? - inflection.call record.to_model.class.model_name + if record.persisted? + args << record.to_model + record.to_model.class.model_name.singular_route_key + else + inflection.call record.to_model.class.model_name + end end route << routing_type(options) -- cgit v1.2.3