2015-01-11 18 views
1

我想这条道路,我想我可以做的命名空间色器件,但不能计算出来,所以我怎么能做到这一点?命名空间嵌套有一项用户

用户/:USER_ID /计费/:bills_id

我有以下的路线设置给用户。

#User routes 
    devise_for :users, controllers: {registrations: "users/registrations", sessions: "users/sessions" } 

    get "https://stackoverflow.com/users/LeastDefender_dashboard" => "users/dashboard#index", as: :users_main 
    get "https://stackoverflow.com/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

或我能得到这个达到相同的效果/用户/计费/:ID我需要的票据信息具体到每一个用户,所以当我做一个索引那只能说明用户账单。我已经有,或者我需要指定用户?我很困惑。 – SupremeA

回答

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 

更多部件RO茨:http://guides.rubyonrails.org/routing.html#adding-member-routes

+0

约色器件和devise_for什么:用户应在命名空间方面去了? – SupremeA

+0

'devise_for:users'通常会上面,如果'users'被管理的资源的资源定义。我编辑了答案来反映这一点。参考文献:https://github.com/plataformatec/devise/wiki/How-To:-Manage-users-through-a-CRUD-interface –

+0

工作就像一个魅力!非常感谢你! – SupremeA

相关问题