我想要这条路,我以为我可以用设计做命名空间但是无法弄明白,所以我该如何实现呢?
用户/:USER_ID /票据/: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_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
答案 0 :(得分:0)
尝试:
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