diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2010-04-09 21:48:35 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2010-04-09 21:48:35 -0700 |
commit | ac0280c39dab272710c25d54810b21c10fff9c52 (patch) | |
tree | 8f5403bdb52126bf79330a972c9a8a0fbe095a60 /actionpack | |
parent | e77a0311e59048f9f11cfda0ce976a93f4629122 (diff) | |
download | rails-ac0280c39dab272710c25d54810b21c10fff9c52.tar.gz rails-ac0280c39dab272710c25d54810b21c10fff9c52.tar.bz2 rails-ac0280c39dab272710c25d54810b21c10fff9c52.zip |
Routes can be selectively namespaced by path or controller module
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG | 19 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 17 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 24 |
3 files changed, 57 insertions, 3 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 6efed4a995..9b18e43516 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,4 +1,21 @@ -*Rails 3.0.0 [Edge] (pending)* +*Rails 3.0.0 [beta 3] (pending)* + +* Routes can be selectively namespaced by path or controller module. [Jeremy Kemper] + + # /users => Admin::UsersController + namespace :controller => 'admin' do + resources :users + end + + # /admin/users => UsersController + namespace :path => 'admin' do + resources :users + end + + # /admin/users => Admin::UsersController + namespace :admin do + resources :users + end * Added #favicon_link_tag, it uses #image_path so in particular the favicon gets an asset ID [fxn] diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 925e91f081..bf707f354a 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -323,8 +323,21 @@ module ActionDispatch scope(controller.to_sym) { yield } end - def namespace(path) - scope(path.to_s, :name_prefix => path.to_s, :controller_namespace => path.to_s) { yield } + def namespace(path_or_options) + options = + case path_or_options + when String, Symbol + path = path_or_options.to_s + { :path => path, + :name_prefix => path, + :controller_namespace => path } + when Hash + { :path => path_or_options[:path], + :controller_namespace => path_or_options[:controller] } + else + raise ArgumentError, "Unknown namespace: #{path_or_options.inspect}" + end + scope(options) { yield } end def constraints(constraints = {}) diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 6ff478aec1..a95f93537b 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -186,6 +186,14 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end resource :dashboard, :constraints => { :ip => /192\.168\.1\.\d{1,3}/ } + + namespace :controller => :api do + resource :token + end + + namespace :path => :api do + resource :me + end end end @@ -942,6 +950,22 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_controller_namespace + with_test_routes do + get '/token' + assert_equal 'api/tokens#show', @response.body + assert_equal '/token', token_path + end + end + + def test_path_namespace + with_test_routes do + get '/api/me' + assert_equal 'mes#show', @response.body + assert_equal '/api/me', me_path + end + end + private def with_test_routes yield |