aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorSammy Larbi <sam@codeodor.com>2014-08-30 17:19:16 -0500
committerSammy Larbi <sam@codeodor.com>2014-08-31 11:39:46 -0500
commit2fae37f0acbb4154fe75c22a892f79e158016866 (patch)
tree9dc3938355e2050227be0ac020e11d74b2d7b8df /actionpack/lib
parenteb8aa4d9fb6d2d2dc196b527d16f2564bcb1ce8e (diff)
downloadrails-2fae37f0acbb4154fe75c22a892f79e158016866.tar.gz
rails-2fae37f0acbb4154fe75c22a892f79e158016866.tar.bz2
rails-2fae37f0acbb4154fe75c22a892f79e158016866.zip
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
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_dispatch/routing/polymorphic_routes.rb3
1 files changed, 2 insertions, 1 deletions
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)