module ActionDispatch::Routing::Mapper::Scoping
def namespace(path, options = {}, &block)
resources :posts
namespace :admin, as: "sekret" do
# generates +sekret_posts_path+ rather than +admin_posts_path+
end
resources :posts
namespace :admin, module: "sekret" do
# maps to +Sekret::PostsController+ rather than +Admin::PostsController+
end
resources :posts
namespace :admin, path: "sekret" do
# accessible through /sekret/posts rather than /admin/posts
Resources#resources.
For options, see Base#match. For +:shallow_path+ option, see
options all default to the name of the namespace.
The +:path+, +:as+, +:module+, +:shallow_path+, and +:shallow_prefix+
=== Options
admin_post DELETE /admin/posts/:id(.:format) admin/posts#destroy
admin_post PATCH/PUT /admin/posts/:id(.:format) admin/posts#update
admin_post GET /admin/posts/:id(.:format) admin/posts#show
edit_admin_post GET /admin/posts/:id/edit(.:format) admin/posts#edit
new_admin_post GET /admin/posts/new(.:format) admin/posts#new
admin_posts POST /admin/posts(.:format) admin/posts#create
admin_posts GET /admin/posts(.:format) admin/posts#index
This generates the following routes:
end
resources :posts
namespace :admin do
Scopes routes to a specific namespace. For example:
def namespace(path, options = {}, &block) path = path.to_s defaults = { module: path, as: options.fetch(:as, path), shallow_path: options.fetch(:path, path), shallow_prefix: options.fetch(:as, path) } path_scope(options.delete(:path) { path }) do scope(defaults.merge!(options), &block) end end