设计用户的命名空间嵌套

Namespace nesting for a devise user

我想要这条路,我想我可以用设计来做命名空间,但我想不通,我该如何实现呢?

用户/: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

当我收集路线时,我得到这个:

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

关于会员路线的更多信息:http://guides.rubyonrails.org/routing.html#adding-member-routes