ActionDispatch::Routing::Mapper::Scoping
module ActionDispatch::Routing::Mapper::Scoping
You may wish to organize groups of controllers under a namespace. Most commonly, you might group a number of administrative controllers under an admin
namespace. You would place these controllers under the app/controllers/admin
directory, and you can group them together in your router:
namespace "admin" do resources :posts, :comments end
This will create a number of routes for each of the posts and comments controller. For Admin::PostsController
, Rails will create:
GET /admin/posts GET /admin/posts/new POST /admin/posts GET /admin/posts/1 GET /admin/posts/1/edit PATCH/PUT /admin/posts/1 DELETE /admin/posts/1
If you want to route /posts (without the prefix /admin) to Admin::PostsCon