From ad31afe63cb50372788e7c3aab15d73ba045a86f Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 6 May 2014 15:45:21 -0700 Subject: only pop records when we get an array --- .../lib/action_dispatch/routing/polymorphic_routes.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb index 1a4adcbb35..192ab51db4 100644 --- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb +++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb @@ -115,28 +115,29 @@ module ActionDispatch end record_list = record_or_hash_or_array.dup + record = record_list.pop when Hash unless record_or_hash_or_array[:id] raise ArgumentError, "Nil location provided. Can't build URI." end opts = record_or_hash_or_array.dup.merge!(opts) - record_list = [opts.delete(:id)] + record_list = [] + record = opts.delete(:id) when nil raise ArgumentError, "Nil location provided. Can't build URI." else - record_list = [record_or_hash_or_array] + record_list = [] + record = record_or_hash_or_array end - record = record_list.pop - inflection = lambda { |name| name.singular_route_key } should_pop = true - if record.try(:persisted?) + if options[:action] == 'new' + elsif record.try(:persisted?) should_pop = false - elsif options[:action] == 'new' else inflection = lambda { |name| name.route_key } end -- cgit v1.2.3