Skip to content
This repository
Browse code

Add RoutingError exception when RouteSet fails to generate a path fro…

…m a Named Route. [Rick Olson]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4733 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 4679e1bf7f83b501f4a9507d530d4c707d16921f 1 parent e9b0284
risk danger olson authored August 09, 2006
5  actionpack/CHANGELOG
... ...
@@ -1,16 +1,15 @@
1 1
 *SVN*
2 2
 
3  
-<<<<<<< .mine
  3
+* Add RoutingError exception when RouteSet fails to generate a path from a Named Route. [Rick Olson]
  4
+
4 5
 * Replace Reloadable with Reloadable::Deprecated. [Nicholas Seckar]
5 6
 
6  
-=======
7 7
 * Deprecation: check whether instance variables have been monkeyed with before assigning them to deprecation proxies. Raises a RuntimeError if so. [Jeremy Kemper]
8 8
 
9 9
 * Add support for the param_name parameter to the auto_complete_field helper. #5026 [david.a.williams@gmail.com]
10 10
 
11 11
 * 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]
12 12
 
13  
->>>>>>> .r4727
14 13
 * Make Routing noisy when an anchor regexp is assigned to a segment. #5674 [francois.beausoleil@gmail.com]
15 14
 
16 15
 * 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]
11  actionpack/lib/action_controller/routing.rb
@@ -981,9 +981,10 @@ def generate_extras(options, recall={})
981 981
       end
982 982
 
983 983
       def generate(options, recall = {}, method=:generate)
984  
-        if options[:use_route]
  984
+        named_route_name = options.delete(:use_route)
  985
+        if named_route_name
985 986
           options = options.dup
986  
-          named_route = named_routes[options.delete(:use_route)]
  987
+          named_route = named_routes[named_route_name]
987 988
           options = named_route.parameter_shell.merge(options)
988 989
         end
989 990
 
@@ -1006,7 +1007,9 @@ def generate(options, recall = {}, method=:generate)
1006 1007
         merged = recall.merge(options)
1007 1008
     
1008 1009
         if named_route
1009  
-          return named_route.generate(options, merged, expire_on)
  1010
+          path = named_route.generate(options, merged, expire_on) 
  1011
+          raise RoutingError, "#{named_route_name}_url failed to generate from #{options.inspect}, missing: #{(named_route.significant_keys - options.keys).inspect}" if path.nil?
  1012
+          return path
1010 1013
         else
1011 1014
           merged[:action] ||= 'index'
1012 1015
           options[:action] ||= 'index'
@@ -1014,7 +1017,7 @@ def generate(options, recall = {}, method=:generate)
1014 1017
           controller = merged[:controller]
1015 1018
           action = merged[:action]
1016 1019
 
1017  
-          raise "Need controller and action!" unless controller && action
  1020
+          raise RoutingError, "Need controller and action!" unless controller && action
1018 1021
           # don't use the recalled keys when determining which routes to check
1019 1022
           routes = routes_by_controller[controller][action][options.keys.sort_by { |x| x.object_id }]
1020 1023
 

0 notes on commit 4679e1b

Please sign in to comment.
Something went wrong with that request. Please try again.