aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-06-01 07:40:41 -0700
committerJosé Valim <jose.valim@gmail.com>2012-06-01 16:42:09 +0200
commit5c565a294224911ba7b3929baabf3465172b40f0 (patch)
tree69cff5315c043708e48b866959be994f48b78893 /actionpack/lib/action_dispatch
parent3449b757da669c08222be58b3743ff9ec48756cc (diff)
downloadrails-5c565a294224911ba7b3929baabf3465172b40f0.tar.gz
rails-5c565a294224911ba7b3929baabf3465172b40f0.tar.bz2
rails-5c565a294224911ba7b3929baabf3465172b40f0.zip
Merge pull request #6588 from nbibler/polymorphic_to_model
Correct the use of to_model in polymorphic routing
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/routing/polymorphic_routes.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
index 8fde667108..86ce7a83b9 100644
--- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
+++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
@@ -95,7 +95,7 @@ module ActionDispatch
end
record = extract_record(record_or_hash_or_array)
- record = record.to_model if record.respond_to?(:to_model)
+ record = convert_to_model(record)
args = Array === record_or_hash_or_array ?
record_or_hash_or_array.dup :
@@ -122,6 +122,8 @@ module ActionDispatch
args.last.kind_of?(Hash) ? args.last.merge!(url_options) : args << url_options
end
+ args.collect! { |a| convert_to_model(a) }
+
(proxy || self).send(named_route, *args)
end
@@ -152,6 +154,10 @@ module ActionDispatch
options[:action] ? "#{options[:action]}_" : ''
end
+ def convert_to_model(object)
+ object.respond_to?(:to_model) ? object.to_model : object
+ end
+
def routing_type(options)
options[:routing_type] || :url
end