aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/routing.rb
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2007-02-04 19:07:08 +0000
committerRick Olson <technoweenie@gmail.com>2007-02-04 19:07:08 +0000
commit7a49cb058f5a8345d55f321d6e6bd9dcac22519a (patch)
tree97d90c030af82ef46da871ff92728d8ac9faa916 /actionpack/lib/action_controller/routing.rb
parent0a454cd73e9644b154d72b573bc58451010f0e1a (diff)
downloadrails-7a49cb058f5a8345d55f321d6e6bd9dcac22519a.tar.gz
rails-7a49cb058f5a8345d55f321d6e6bd9dcac22519a.tar.bz2
rails-7a49cb058f5a8345d55f321d6e6bd9dcac22519a.zip
fix form_for example in ActionController::Resources documentation. Closes #7362 [gnarg], Added enhanced docs to routing assertions. Closes #7359 [Rob Sanheim], improve error message for Routing for named routes. Closes #7346 [Rob Sanheim]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6113 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller/routing.rb')
-rw-r--r--actionpack/lib/action_controller/routing.rb19
1 files changed, 17 insertions, 2 deletions
diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb
index 5b888443d8..58207eed74 100644
--- a/actionpack/lib/action_controller/routing.rb
+++ b/actionpack/lib/action_controller/routing.rb
@@ -1240,8 +1240,11 @@ module ActionController
if named_route
path = named_route.generate(options, merged, expire_on)
- raise RoutingError, "#{named_route_name}_url failed to generate from #{options.inspect}, expected: #{named_route.requirements.inspect}, diff: #{named_route.requirements.diff(options).inspect}" if path.nil?
- return path
+ if path.nil?
+ raise_named_route_error(options, named_route, named_route_name)
+ else
+ return path
+ end
else
merged[:action] ||= 'index'
options[:action] ||= 'index'
@@ -1269,6 +1272,18 @@ module ActionController
raise RoutingError, "No route matches #{options.inspect}"
end
+
+ # try to give a helpful error message when named route generation fails
+ def raise_named_route_error(options, named_route, named_route_name)
+ diff = named_route.requirements.diff(options)
+ unless diff.empty?
+ raise RoutingError, "#{named_route_name}_url failed to generate from #{options.inspect}, expected: #{named_route.requirements.inspect}, diff: #{named_route.requirements.diff(options).inspect}"
+ else
+ required_segments = named_route.segments.select {|seg| (!seg.optional?) && (!seg.is_a?(DividerSegment)) }
+ required_keys_or_values = required_segments.map { |seg| seg.key rescue seg.value } # we want either the key or the value from the segment
+ raise RoutingError, "#{named_route_name}_url failed to generate from #{options.inspect} - you may have ambiguous routes, or you may need to supply additional parameters for this route. content_url has the following required parameters: #{required_keys_or_values.inspect} - are they all satisifed?"
+ end
+ end
def recognize(request)
params = recognize_path(request.path, extract_request_environment(request))