aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
authorChris Carter <chris.carter@unboxedconsulting.com>2016-09-20 10:42:26 +0100
committerChris Carter <chris.carter@unboxedconsulting.com>2016-10-03 09:52:14 +0100
commit0b32e2dff353ceb9bc463787c5897ecae7302ab7 (patch)
treeb549472a55b336e05bbad52b98630f360f53f63f /actionpack/lib/action_dispatch
parent2d6c14bca25c5629e431a802c3053bad1e378fcc (diff)
downloadrails-0b32e2dff353ceb9bc463787c5897ecae7302ab7.tar.gz
rails-0b32e2dff353ceb9bc463787c5897ecae7302ab7.tar.bz2
rails-0b32e2dff353ceb9bc463787c5897ecae7302ab7.zip
Show an "unmatched constraints" error for mismatching and present params
Currently a misleading "missing required keys" error is thrown when a param fails to match the constraints of a particular route. This commit ensures that these params are recognised as unmatching rather than missing. Note: this means that a different error message will be provided between optimized and non-optimized path helpers, due to the fact that the former does not check constraints when matching routes. Fixes #26470.
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/journey/formatter.rb6
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb2
2 files changed, 6 insertions, 2 deletions
diff --git a/actionpack/lib/action_dispatch/journey/formatter.rb b/actionpack/lib/action_dispatch/journey/formatter.rb
index a289c34e8b..dc8b24b089 100644
--- a/actionpack/lib/action_dispatch/journey/formatter.rb
+++ b/actionpack/lib/action_dispatch/journey/formatter.rb
@@ -44,8 +44,12 @@ module ActionDispatch
return [route.format(parameterized_parts), params]
end
+ unmatched_keys = (missing_keys || []) & constraints.keys
+ missing_keys = (missing_keys || []) - unmatched_keys
+
message = "No route matches #{Hash[constraints.sort_by { |k,v| k.to_s }].inspect}"
- message << " missing required keys: #{missing_keys.sort.inspect}" if missing_keys && !missing_keys.empty?
+ message << ", missing required keys: #{missing_keys.sort.inspect}" if missing_keys && !missing_keys.empty?
+ message << ", possible unmatched constraints: #{unmatched_keys.sort.inspect}" if unmatched_keys && !unmatched_keys.empty?
raise ActionController::UrlGenerationError, message
end
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 5abf59402d..a1bc357c8b 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -210,7 +210,7 @@ module ActionDispatch
}
constraints = Hash[@route.requirements.merge(params).sort_by { |k,v| k.to_s }]
message = "No route matches #{constraints.inspect}"
- message << " missing required keys: #{missing_keys.sort.inspect}"
+ message << ", missing required keys: #{missing_keys.sort.inspect}"
raise ActionController::UrlGenerationError, message
end