From c7df5bd6ac256cf75631f8c59c1de1f96df02b17 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 7 Jun 2007 21:35:01 +0000 Subject: More nested polymorphic url helper fixes. Closes #6432, references #8601. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6960 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/polymorphic_routes.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/polymorphic_routes.rb b/actionpack/lib/action_controller/polymorphic_routes.rb index 6c21bc27c5..d6c57d1207 100644 --- a/actionpack/lib/action_controller/polymorphic_routes.rb +++ b/actionpack/lib/action_controller/polymorphic_routes.rb @@ -3,7 +3,14 @@ module ActionController def polymorphic_url(record_or_hash_or_array, options = {}) record = extract_record(record_or_hash_or_array) - args = [] + args = case record_or_hash_or_array + when Hash: [record_or_hash_or_array[:id]] + when Array: record_or_hash_or_array.dup + else [record_or_hash_or_array] + end + + args.pop # Remove the base record; we only need it in one case + inflection = case when options[:action] == "new" @@ -11,10 +18,10 @@ module ActionController when record.respond_to?(:new_record?) && record.new_record? :plural else - args = [record_or_hash_or_array] + args.push(record) # Put the base record back in :singular end - + named_route = build_named_route_call(record_or_hash_or_array, inflection, options) send(named_route, *args) end -- cgit v1.2.3