From 2fae37f0acbb4154fe75c22a892f79e158016866 Mon Sep 17 00:00:00 2001 From: Sammy Larbi Date: Sat, 30 Aug 2014 17:19:16 -0500 Subject: Allow polymorphic routes with nil when a route can still be drawn Suppose you have two resources routed in the following manner: ```ruby resources :blogs do resources :posts end resources :posts ``` When using polymorphic resource routing like `url_for([@blog, @post])`, and `@blog` is `nil` Rails should still try to match the route to the top-level posts resource. Fixes #16754 --- actionpack/lib/action_dispatch/routing/polymorphic_routes.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb index 427a5674bd..f15868d37e 100644 --- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb +++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb @@ -197,7 +197,8 @@ module ActionDispatch case record_or_hash_or_array when Array - if record_or_hash_or_array.empty? || record_or_hash_or_array.include?(nil) + record_or_hash_or_array = record_or_hash_or_array.compact + if record_or_hash_or_array.empty? raise ArgumentError, "Nil location provided. Can't build URI." end if record_or_hash_or_array.first.is_a?(ActionDispatch::Routing::RoutesProxy) -- cgit v1.2.3