diff options
author | José Valim <jose.valim@gmail.com> | 2010-05-17 17:36:34 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-05-17 17:39:32 +0200 |
commit | 107c6381a0a3403461f1dc00e140565028af73e1 (patch) | |
tree | 62f5c130b243b4dd7196ece86609b8b7a9f91766 | |
parent | 5371242384171dc0255716e31e9257ddeec17d10 (diff) | |
download | rails-107c6381a0a3403461f1dc00e140565028af73e1.tar.gz rails-107c6381a0a3403461f1dc00e140565028af73e1.tar.bz2 rails-107c6381a0a3403461f1dc00e140565028af73e1.zip |
Allow root to be given in the resources scope without need to specify :on => collection.
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 5 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 12 |
2 files changed, 16 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 4b02c2deb3..8a8d21c434 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -693,6 +693,11 @@ module ActionDispatch super end + def root(options={}) + options[:on] ||= :collection if @scope[:scope_level] == :resources + super(options) + end + protected def parent_resource #:nodoc: @scope[:scope_level_resource] diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 651a7a6be0..180889ddf2 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -186,6 +186,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end resources :products, :constraints => { :id => /\d{4}/ } do + root :to => "products#root" + get :favorite, :on => :collection resources :images end @@ -963,7 +965,9 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get '/products/1' assert_equal 'pass', @response.headers['X-Cascade'] get '/products' - assert_equal 'products#index', @response.body + assert_equal 'products#root', @response.body + get '/products/favorite' + assert_equal 'products#favorite', @response.body get '/products/0001' assert_equal 'products#show', @response.body @@ -981,6 +985,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_root_works_in_the_resources_scope + get '/products' + assert_equal 'products#root', @response.body + assert_equal '/products', products_root_path + end + def test_module_scope with_test_routes do get '/token' |