会员路线有困难

时间:2013-11-21 21:02:43

标签: ruby-on-rails devise routes ruby-on-rails-4

更新:这是一个可怕的错误 - 我正在更新错误的路线文件! 这确实有效:get 'users/:id/groups/' => 'users#groups'

我希望能够看到属于特定用户的群组,但我无法设置可解决的路线:

/users/:id/groups

出于某种原因。我猜测设计正在阻碍,或许。

我尝试了以下内容:

resources :users 

match '/users/:id/groups', to: 'users#groups', via: :get

resources :users do
  member do
    get 'groups'
  end
end

当我致电rake routes时,这样的路线永远不会出现:

$ rake routes
              Prefix Verb   URI Pattern                          Controller#Action
              groups GET    /groups(.:format)                    groups#index
                     POST   /groups(.:format)                    groups#create
           new_group GET    /groups/new(.:format)                groups#new
          edit_group GET    /groups/:id/edit(.:format)           groups#edit
               group GET    /groups/:id(.:format)                groups#show
                     PATCH  /groups/:id(.:format)                groups#update
                     PUT    /groups/:id(.:format)                groups#update
                     DELETE /groups/:id(.:format)                groups#destroy
            calendar GET    /calendar(/:year(/:month))(.:format) calendar#index {:year=>/\d{4}/, :month=>/\d{1,2}/}
                root GET    /                                    calendar#index
    new_user_session GET    /users/sign_in(.:format)             devise/sessions#new
        user_session POST   /users/sign_in(.:format)             devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format)            devise/sessions#destroy
       user_password POST   /users/password(.:format)            devise/passwords#create
   new_user_password GET    /users/password/new(.:format)        devise/passwords#new
  edit_user_password GET    /users/password/edit(.:format)       devise/passwords#edit
                     PATCH  /users/password(.:format)            devise/passwords#update
                     PUT    /users/password(.:format)            devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)              registrations#cancel
       user_registration POST   /users(.:format)                     registrations#create
   new_user_registration GET    /users/sign_up(.:format)             registrations#new
  edit_user_registration GET    /users/edit(.:format)                registrations#edit
                         PATCH  /users(.:format)                     registrations#update
                         PUT    /users(.:format)                     registrations#update
                         DELETE /users(.:format)                     registrations#destroy
       user_confirmation POST   /users/confirmation(.:format)        devise/confirmations#create
   new_user_confirmation GET    /users/confirmation/new(.:format)    devise/confirmations#new
                         GET    /users/confirmation(.:format)        devise/confirmations#show
  accept_user_invitation GET    /users/invitation/accept(.:format)   devise/invitations#edit
  remove_user_invitation GET    /users/invitation/remove(.:format)   devise/invitations#destroy
         user_invitation POST   /users/invitation(.:format)          devise/invitations#create
     new_user_invitation GET    /users/invitation/new(.:format)      devise/invitations#new
                        PATCH  /users/invitation(.:format)          devise/invitations#update
                        PUT    /users/invitation(.:format)          devise/invitations#update
                   users GET    /users(.:format)                     users#index
                          POST   /users(.:format)                     users#create
                new_user GET    /users/new(.:format)                 users#new
               edit_user GET    /users/:id/edit(.:format)            users#edit
                    user GET    /users/:id(.:format)                 users#show
                         PATCH  /users/:id(.:format)                 users#update
                         PUT    /users/:id(.:format)                 users#update
                         DELETE /users/:id(.:format)                 users#destroy
                  events GET    /events(.:format)                    events#index
                         POST   /events(.:format)                    events#create
               new_event GET    /events/new(.:format)                events#new
              edit_event GET    /events/:id/edit(.:format)           events#edit
                   event GET    /events/:id(.:format)                events#show
                         PATCH  /events/:id(.:format)                events#update
                         PUT    /events/:id(.:format)                events#update
                         DELETE /events/:id(.:format)                events#destroy

1 个答案:

答案 0 :(得分:0)

为什么在尝试嵌套资源时指定成员?你试过简单吗

resources :users do
  resources :groups, only: :index
end