aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-05-06 16:08:51 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-05-12 15:54:44 -0700
commit34b2ded2ff632df8bbb3fe4a2ff1d9dbcbcba85b (patch)
tree8032d8509d4c3b2aa3c7bc3233dcacc605444bc0 /actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
parenta572a0e75403ed0fefa27a0e602b73e1b6edb478 (diff)
downloadrails-34b2ded2ff632df8bbb3fe4a2ff1d9dbcbcba85b.tar.gz
rails-34b2ded2ff632df8bbb3fe4a2ff1d9dbcbcba85b.tar.bz2
rails-34b2ded2ff632df8bbb3fe4a2ff1d9dbcbcba85b.zip
only test `persisted?` on the record once
also avoid the case of calling `persisted?` on something that doesn't respond to it
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/polymorphic_routes.rb')
-rw-r--r--actionpack/lib/action_dispatch/routing/polymorphic_routes.rb10
1 files changed, 7 insertions, 3 deletions
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)