为资源指定 "subdirectory"-路径
Specifying "subdirectory"-path for resources
我想要 Team
的以下足智多谋的路线:
/admin/users/teams
/admin/users/team/new
/admin/users/team/:id
etc...
使用以下路线助手
admin_teams_path
new_admin_teams_path
edit_admin_teams_path
etc...
但只有我知道并使用的命名空间
namespace :admin do
namespace :users do
resources :teams, except: [:index]
end
end
我刚得到这些长途路线助手,里面有 "users":
admin_users_teams_path
new_admin_users_teams_path
edit_admin_users_teams_path
删除 users
命名空间并在您的路由中使用 path
选项:
namespace :admin, path: "admin/users" do
resources :teams, except: [:index]
end
给出了以下路线:
$ rake routes
admin_teams POST /admin/users/teams(.:format) admin/teams#create
new_admin_team GET /admin/users/teams/new(.:format) admin/teams#new
edit_admin_team GET /admin/users/teams/:id/edit(.:format) admin/teams#edit
admin_team GET /admin/users/teams/:id(.:format) admin/teams#show
PATCH /admin/users/teams/:id(.:format) admin/teams#update
PUT /admin/users/teams/:id(.:format) admin/teams#update
DELETE /admin/users/teams/:id(.:format) admin/teams#destroy
我想要 Team
的以下足智多谋的路线:
/admin/users/teams
/admin/users/team/new
/admin/users/team/:id
etc...
使用以下路线助手
admin_teams_path
new_admin_teams_path
edit_admin_teams_path
etc...
但只有我知道并使用的命名空间
namespace :admin do
namespace :users do
resources :teams, except: [:index]
end
end
我刚得到这些长途路线助手,里面有 "users":
admin_users_teams_path
new_admin_users_teams_path
edit_admin_users_teams_path
删除 users
命名空间并在您的路由中使用 path
选项:
namespace :admin, path: "admin/users" do
resources :teams, except: [:index]
end
给出了以下路线:
$ rake routes
admin_teams POST /admin/users/teams(.:format) admin/teams#create
new_admin_team GET /admin/users/teams/new(.:format) admin/teams#new
edit_admin_team GET /admin/users/teams/:id/edit(.:format) admin/teams#edit
admin_team GET /admin/users/teams/:id(.:format) admin/teams#show
PATCH /admin/users/teams/:id(.:format) admin/teams#update
PUT /admin/users/teams/:id(.:format) admin/teams#update
DELETE /admin/users/teams/:id(.:format) admin/teams#destroy