namespace
namespace :admin do
resources :posts
end默认对应:
# 中间层 helper 方法 # 最外层网址 # 最里层 Controller#action
admin_posts GET /admin/posts(.:format) admin/posts#index
admin_posts POST /admin/posts(.:format) admin/posts#create
new_admin_post GET /admin/posts/new(.:format) admin/posts#new
edit_admin_post GET /admin/posts/:id/edit(.:format) admin/posts#edit
admin_post GET /admin/posts/:id(.:format) admin/posts#show
admin_post PATCH/PUT /admin/posts/:id(.:format) admin/posts#update
admin_post DELETE /admin/posts/:id(.:format) admin/posts#destroy1) 使用 :path 更改最外层网址:
# 使用 /sekret/posts 而不是 /admin/posts
namespace :admin, path: "sekret" do
resources :posts
end2) 使用 :module 更改最里层 Controller#action:
# 使用 Sekret::PostsController 而不是 Admin::PostsController
namespace :admin, module: "sekret" do
resources :posts
end3) 使用 :as 更改中间层 helper 方法:
4) 此外:
最后更新于
这有帮助吗?