1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Dial back from 'namespace :controller => ...' to 'scope :module => ...'

This commit is contained in:
Jeremy Kemper 2010-04-09 23:09:15 -07:00
parent 561d9eff0c
commit 7353fc1595
3 changed files with 13 additions and 35 deletions

View file

@ -1,20 +1,10 @@
*Rails 3.0.0 [beta 3] (pending)*
* Routes can be selectively namespaced by path or controller module. [Jeremy Kemper]
* Routes can be scoped by 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
# /session => Auth::SessionsController
scope :module => 'auth' do
resource :session
end
* Added #favicon_link_tag, it uses #image_path so in particular the favicon gets an asset ID [fxn]

View file

@ -323,21 +323,9 @@ module ActionDispatch
scope(controller.to_sym) { yield }
end
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 }
def namespace(path)
path = path.to_s
scope(:path => path, :name_prefix => path, :module => path) { yield }
end
def constraints(constraints = {})
@ -376,12 +364,12 @@ module ActionDispatch
parent ? "#{parent}_#{child}" : child
end
def merge_controller_namespace_scope(parent, child)
def merge_module_scope(parent, child)
parent ? "#{parent}/#{child}" : child
end
def merge_controller_scope(parent, child)
@scope[:controller_namespace] ? "#{@scope[:controller_namespace]}/#{child}" : child
@scope[:module] ? "#{@scope[:module]}/#{child}" : child
end
def merge_resources_path_names_scope(parent, child)

View file

@ -187,11 +187,11 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
resource :dashboard, :constraints => { :ip => /192\.168\.1\.\d{1,3}/ }
namespace :controller => :api do
scope :module => 'api' do
resource :token
end
namespace :path => :api do
scope :path => 'api' do
resource :me
match '/' => 'mes#index'
end
@ -951,7 +951,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
def test_controller_namespace
def test_module_scope
with_test_routes do
get '/token'
assert_equal 'api/tokens#show', @response.body
@ -959,7 +959,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
def test_path_namespace
def test_path_scope
with_test_routes do
get '/api/me'
assert_equal 'mes#show', @response.body