method
namespace
v3.0.0 -
Show latest stable
- Class:
ActionDispatch::Routing::Mapper::Scoping
namespace(path, options = {})public
No documentation available.
# File actionpack/lib/action_dispatch/routing/mapper.rb, line 369
def namespace(path, options = {})
path = path.to_s
options = { :path => path, :as => path, :module => path,
:shallow_path => path, :shallow_prefix => path }.merge!(options)
scope(options) { yield }
end 2Notes
Without module
If you want to have only the path prefix without namespacing your controller, pass :module => false.
Normal:
namespace :account do
resources :transactions, :only => [:index]
end
account_transactions GET /account/transactions(.:format)
{:controller=>"account/transactions", :action=>"index"}
With :module => false:
namespace :account, :module => false do
resources :transactions, :only => [:index]
end
account_transactions GET /account/transactions(.:format)
{:controller=>"transactions", :action=>"index"}
with a params constant
If you want to have a params with the same value on all of the urls in this namespace, you can write this :
==== with a constant param :admin set to true namespace :admin, :admin => true do resources :posts end
all of the urls like /admin/post have a param :admin with the value true.
==== It works also with : scope 'admin', :admin => true do ... end
match 'administration', :admin => true => 'posts#index'
get 'administration', :admin => true
etc...