Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow Routes to generate all urls for a set of options by specifying …

…:generate_all => true. References #1739.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6082 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 2cc9c8135c57671013a0b89fd683654cb6782676 1 parent 17a9405
@seckar seckar authored
View
2  actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Allow Routes to generate all urls for a set of options by specifying :generate_all => true. Allows caching to properly set or expire all paths for a resource. References #1739. [Nicholas Seckar]
+
* Change the query parser to map empty GET params to "" rather than nil. Closes #5694. [Nicholas Seckar]
* date_select and datetime_select take a :default option. #7052 [nik.wakelin]
View
9 actionpack/lib/action_controller/routing.rb
@@ -1214,6 +1214,7 @@ def generate_extras(options, recall={})
def generate(options, recall = {}, method=:generate)
named_route_name = options.delete(:use_route)
+ generate_all = options.delete(:generate_all)
if named_route_name
named_route = named_routes[named_route_name]
options = named_route.parameter_shell.merge(options)
@@ -1249,6 +1250,14 @@ def generate(options, recall = {}, method=:generate)
action = merged[:action]
raise RoutingError, "Need controller and action!" unless controller && action
+
+ if generate_all
+ # Used by caching to expire all paths for a resource
+ return routes.collect do |route|
+ route.send(method, options, merged, expire_on)
+ end.compact
+ end
+
# 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 }]
View
14 actionpack/test/controller/routing_test.rb
@@ -1719,6 +1719,20 @@ def test_query_params_will_be_shown_when_recalled
)
end
+ def test_generate_all
+ set.draw do |map|
+ map.connect 'show_post/:id', :controller => 'post', :action => 'show'
+ map.connect ':controller/:action/:id'
+ end
+ all = set.generate(
+ {:action => 'show', :id => 10, :generate_all => true},
+ {:controller => 'post', :action => 'show'}
+ )
+ assert_equal 2, all.length
+ assert_equal '/show_post/10', all.first
+ assert_equal '/post/show/10', all.last
+ end
+
end
class RoutingTest < Test::Unit::TestCase
Please sign in to comment.
Something went wrong with that request. Please try again.