aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/routing.rb16
-rw-r--r--actionpack/test/controller/routing_test.rb12
3 files changed, 26 insertions, 4 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 7b6858ebb1..db1a67f8f9 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added named_route method to RouteSet instances so that RouteSet instance methods do not prevent certain names from being used. [Nicholas Seckar]
+
* Fixed routes so that routes which do not specify :action in the path or in the requirements have a default of :action => 'index', In addition, fixed url generation so that :action => 'index' does not need to be provided for such urls. [Nicholas Seckar, Markjuh]
* Worked around a Safari bug where it wouldn't pass headers through if the response was zero length by having render :nothing return ' ' instead of ''
diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb
index fd9904a20e..82b12f3a7b 100644
--- a/actionpack/lib/action_controller/routing.rb
+++ b/actionpack/lib/action_controller/routing.rb
@@ -573,13 +573,21 @@ module ActionController
def each(&block) @routes.each(&block) end
- def method_missing(name, *args)
- return super(name, *args) unless (1..2).include?(args.length)
-
- route = connect(*args)
+ # Defines a new named route with the provided name and arguments.
+ # This method need only be used when you wish to use a name that a RouteSet instance
+ # method exists for, such as categories.
+ #
+ # For example, map.categories '/categories', :controller => 'categories' will not work
+ # due to RouteSet#categories.
+ def named_route(name, path, hash = {})
+ route = connect(path, hash)
NamedRoutes.name_route(route, name)
route
end
+
+ def method_missing(name, *args)
+ (1..2).include?(args.length) ? named_route(name, *args) : super(name, *args)
+ end
def extra_keys(options, recall = {})
generate(options.dup, recall).last.keys
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index c0bc92f6db..23d741a58f 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -862,6 +862,18 @@ class RouteSetTests < Test::Unit::TestCase
assert_equal ['/content/hi', {}], rs.generate({:controller => 'content', :action => 'hi'})
end
end
+
+ def test_named_route_method
+ rs.draw do
+ assert_raises(ArgumentError) { rs.categories 'categories', :controller => 'content', :action => 'categories' }
+
+ rs.named_route :categories, 'categories', :controller => 'content', :action => 'categories'
+ rs.connect ':controller/:action/:id'
+ end
+
+ assert_equal ['/categories', {}], rs.generate(:controller => 'content', :action => 'categories')
+ assert_equal ['/content/hi', {}], rs.generate({:controller => 'content', :action => 'hi'})
+ end
end