Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 7353fc15957aa3b32eae8cf495701a7163cf8dbc 1 parent 561d9ef
@jeremy jeremy authored
View
18 actionpack/CHANGELOG
@@ -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
22 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -323,21 +323,9 @@ def controller(controller)
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 @@ def merge_name_prefix_scope(parent, child)
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
8 actionpack/test/dispatch/routing_test.rb
@@ -187,11 +187,11 @@ def self.matches?(request)
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 @@ def test_resource_constraints
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 @@ def test_controller_namespace
end
end
- def test_path_namespace
+ def test_path_scope
with_test_routes do
get '/api/me'
assert_equal 'mes#show', @response.body
Please sign in to comment.
Something went wrong with that request. Please try again.