Ruby on rails 设计用户的命名空间嵌套
我想要这条路,我想我可以用designe做名称空间,但我想不出来,所以我如何才能做到这一点 用户/:用户id/账单/:账单id 我为用户设置了以下路由Ruby on rails 设计用户的命名空间嵌套,ruby-on-rails,devise,routes,namespaces,Ruby On Rails,Devise,Routes,Namespaces,我想要这条路,我想我可以用designe做名称空间,但我想不出来,所以我如何才能做到这一点 用户/:用户id/账单/:账单id 我为用户设置了以下路由 #User routes devise_for :users, controllers: {registrations: "users/registrations", sessions: "users/sessions" } get "/users/LeastDefender_dashboard" => "users/dashbo
#User routes
devise_for :users, controllers: {registrations: "users/registrations", sessions: "users/sessions" }
get "/users/LeastDefender_dashboard" => "users/dashboard#index", as: :users_main
get "/users/why_choose_LeastDefender" => "users/landing#index", as: :users_why
namespace :users do
resources :landing, only: [:index, :show]
resources :bills
resources :dashboard
get 'landing', to: 'landing#index'
get 'dashboard', to: 'dashboard#index'
end
我怎样才能做到这一点
用户/:用户id/账单/:账单id
当我搜索路线时,我得到以下信息:
users_bills GET /users/bills(.:format)
users/bills#index POST /users/bills(.:format) users/bills#create
new_users_bill GET /users/bills/new(.:format) users/bills#new
edit_users_bill GET /users/bills/:id/edit(.:format) users/bills#edit
users_bill GET /users/bills/:id(.:format) users/bills#show
PATCH /users/bills/:id(.:format) users/bills#update
PUT /users/bills/:id(.:format) users/bills#update
DELETE /users/bills/:id(.:format) users/bills#destroy
尝试:
它给出了以下路线:
bills GET /users/:id/bills(.:format) bills#index
POST /users/:id/bills(.:format) bills#create
new_bill GET /users/:id/bills/new(.:format) bills#new
edit_bill GET /users/:id/bills/:id/edit(.:format) bills#edit
bill GET /users/:id/bills/:id(.:format) bills#show
PATCH /users/:id/bills/:id(.:format) bills#update
PUT /users/:id/bills/:id(.:format) bills#update
DELETE /users/:id/bills/:id(.:format) bills#destroy
关于会员路线的更多信息:或者我可以得到同样效果的信息吗/users/bills/:id我需要针对每个用户的账单信息,所以当我做索引时,它只显示用户的账单。我是否已经拥有该功能,还是需要指定用户?我很困惑。关于designe和design_for:用户应该在名称空间区域吗?
design_for:users
通常高于资源定义,如果用户
作为资源进行管理。我编辑了答案以反映这一点。裁判:工作得很有魅力!非常感谢你!
bills GET /users/:id/bills(.:format) bills#index
POST /users/:id/bills(.:format) bills#create
new_bill GET /users/:id/bills/new(.:format) bills#new
edit_bill GET /users/:id/bills/:id/edit(.:format) bills#edit
bill GET /users/:id/bills/:id(.:format) bills#show
PATCH /users/:id/bills/:id(.:format) bills#update
PUT /users/:id/bills/:id(.:format) bills#update
DELETE /users/:id/bills/:id(.:format) bills#destroy