Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refine the deprecated route check to explicitly check whether the fut…

…ure route pick comes before the deprecated route that was found.
  • Loading branch information...
commit 061b0ba6cbe6874b3c8b7edb372707411e719da6 1 parent dbc62ad
@jeremy jeremy authored
Showing with 6 additions and 5 deletions.
  1. +6 −5 actionpack/lib/action_controller/routing/route_set.rb
View
11 actionpack/lib/action_controller/routing/route_set.rb
@@ -405,17 +405,18 @@ def generate(options, recall = {}, method=:generate)
end
# don't use the recalled keys when determining which routes to check
- routes = routes_by_controller[controller][action][options.reject {|k,v| !v}.keys.sort_by { |x| x.object_id }]
+ future_routes, deprecated_routes = routes_by_controller[controller][action][options.reject {|k,v| !v}.keys.sort_by { |x| x.object_id }]
+ no_worries = future_routes == deprecated_routes
- routes[1].each_with_index do |route, index|
+ deprecated_routes.each_with_index do |route, index|
results = route.__send__(method, options, merged, expire_on)
if results && (!results.is_a?(Array) || results.first)
# Compare results with Rails 3.0 behavior
- if routes[0][index] != route
- routes[0].each do |route2|
+ unless no_worries
+ future_routes.each_with_index do |route2, index2|
new_results = route2.__send__(method, options, merged, expire_on)
- if new_results && (!new_results.is_a?(Array) || new_results.first)
+ if new_results && (!new_results.is_a?(Array) || new_results.first) && index2 < future_routes.index(route)
ActiveSupport::Deprecation.warn "The URL you generated will use the first matching route in routes.rb rather than the \"best\" match. " +
"In Rails 3.0 #{new_results} will be generated instead of #{results}"
break
Please sign in to comment.
Something went wrong with that request. Please try again.