From 4679e1bf7f83b501f4a9507d530d4c707d16921f Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Wed, 9 Aug 2006 00:02:08 +0000 Subject: [PATCH] Add RoutingError exception when RouteSet fails to generate a path from a Named Route. [Rick Olson] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4733 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 5 ++--- actionpack/lib/action_controller/routing.rb | 11 +++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 92dee9b40f..1b844f46b3 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,16 +1,15 @@ *SVN* -<<<<<<< .mine +* Add RoutingError exception when RouteSet fails to generate a path from a Named Route. [Rick Olson] + * Replace Reloadable with Reloadable::Deprecated. [Nicholas Seckar] -======= * Deprecation: check whether instance variables have been monkeyed with before assigning them to deprecation proxies. Raises a RuntimeError if so. [Jeremy Kemper] * Add support for the param_name parameter to the auto_complete_field helper. #5026 [david.a.williams@gmail.com] * Deprecation! @params, @session, @flash will be removed after 1.2. Use the corresponding instance methods instead. You'll get printed warnings during tests and logged warnings in dev mode when you access either instance variable directly. [Jeremy Kemper] ->>>>>>> .r4727 * Make Routing noisy when an anchor regexp is assigned to a segment. #5674 [francois.beausoleil@gmail.com] * Added months and years to the resolution of DateHelper#distance_of_time_in_words, such that "60 days ago" becomes "2 months ago" #5611 [pjhyett@gmail.com] diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 5d5f1809b7..8dd5f37a8b 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -981,9 +981,10 @@ module ActionController end def generate(options, recall = {}, method=:generate) - if options[:use_route] + named_route_name = options.delete(:use_route) + if named_route_name options = options.dup - named_route = named_routes[options.delete(:use_route)] + named_route = named_routes[named_route_name] options = named_route.parameter_shell.merge(options) end @@ -1006,7 +1007,9 @@ module ActionController merged = recall.merge(options) if named_route - return named_route.generate(options, merged, expire_on) + path = named_route.generate(options, merged, expire_on) + raise RoutingError, "#{named_route_name}_url failed to generate from #{options.inspect}, missing: #{(named_route.significant_keys - options.keys).inspect}" if path.nil? + return path else merged[:action] ||= 'index' options[:action] ||= 'index' @@ -1014,7 +1017,7 @@ module ActionController controller = merged[:controller] action = merged[:action] - raise "Need controller and action!" unless controller && action + raise RoutingError, "Need controller and action!" unless controller && action # don't use the recalled keys when determining which routes to check routes = routes_by_controller[controller][action][options.keys.sort_by { |x| x.object_id }]