gpt4 book ai didi

ruby-on-rails - 设计用户的命名空间嵌套

转载 作者:行者123 更新时间:2023-12-04 16:57:42 24 4
gpt4 key购买 nike

我想要这条路径,我想我可以用设计来做命名空间,但无法弄清楚,所以我该如何实现呢?

用户/:user_id/bills/:bills_id

我为用户设置了以下路线。

#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

我怎样才能做到这一点?

用户/:user_id/bills/:bills_id

当我 rake 路线时,我得到了这个:
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

最佳答案

尝试:

devise_for :users ...

resources :users do
member do
resources :bills
end
end

它提供了以下路线:
                                  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

更多成员(member)路线: http://guides.rubyonrails.org/routing.html#adding-member-routes

关于ruby-on-rails - 设计用户的命名空间嵌套,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27891526/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com