嵌套标识不存在

时间:2014-06-17 08:00:09

标签: ruby-on-rails routes

我的routes.rb:

Rails.application.routes.draw do
  root 'tickets#new'

  devise_for :staffs

  resource :staff, only: [:edit, :new] do
    collection do
      patch :update_password
      patch :create_member
      get :list
    end
  end 

  resources :staffs do
    resource :tickets
  end

  resources :tickets do
    collection do
      get :suggestions
      get :search_form
      post :search
      get :broadcast
      get '/token/:token', :action => 'show', :as => 'show'
    end
    resource :posts     
  end

  resources :pictures

end

rake routes:

                   Prefix Verb   URI Pattern                              Contro
ller#Action
                     root GET    /                                        ticket
s#new
        new_staff_session GET    /staffs/sign_in(.:format)                devise
/sessions#new
            staff_session POST   /staffs/sign_in(.:format)                devise
/sessions#create
    destroy_staff_session GET    /staffs/sign_out(.:format)               devise
/sessions#destroy
           staff_password POST   /staffs/password(.:format)               devise
/passwords#create
       new_staff_password GET    /staffs/password/new(.:format)           devise
/passwords#new
      edit_staff_password GET    /staffs/password/edit(.:format)          devise
/passwords#edit
                          PATCH  /staffs/password(.:format)               devise
/passwords#update
                          PUT    /staffs/password(.:format)               devise
/passwords#update
cancel_staff_registration GET    /staffs/cancel(.:format)                 devise
/registrations#cancel
       staff_registration POST   /staffs(.:format)                        devise
/registrations#create
   new_staff_registration GET    /staffs/sign_up(.:format)                devise
/registrations#new
  edit_staff_registration GET    /staffs/edit(.:format)                   devise
/registrations#edit
                          PATCH  /staffs(.:format)                        devise
/registrations#update
                          PUT    /staffs(.:format)                        devise
/registrations#update
                          DELETE /staffs(.:format)                        devise
/registrations#destroy
    update_password_staff PATCH  /staff/update_password(.:format)         staffs
#update_password
      create_member_staff PATCH  /staff/create_member(.:format)           staffs
#create_member
               list_staff GET    /staff/list(.:format)                    staffs
#list
                new_staff GET    /staff/new(.:format)                     staffs
#new
               edit_staff GET    /staff/edit(.:format)                    staffs
#edit
            staff_tickets POST   /staffs/:staff_id/tickets(.:format)      ticket
s#create
        new_staff_tickets GET    /staffs/:staff_id/tickets/new(.:format)  ticket
s#new
       edit_staff_tickets GET    /staffs/:staff_id/tickets/edit(.:format) ticket
s#edit
                          GET    /staffs/:staff_id/tickets(.:format)      ticket
s#show
                          PATCH  /staffs/:staff_id/tickets(.:format)      ticket
s#update
                          PUT    /staffs/:staff_id/tickets(.:format)      ticket
s#update
                          DELETE /staffs/:staff_id/tickets(.:format)      ticket
s#destroy
                   staffs GET    /staffs(.:format)                        staffs
#index
                          POST   /staffs(.:format)                        staffs
#create
                          GET    /staffs/new(.:format)                    staffs
#new
                          GET    /staffs/:id/edit(.:format)               staffs
#edit
                    staff GET    /staffs/:id(.:format)                    staffs
#show
                          PATCH  /staffs/:id(.:format)                    staffs
#update
                          PUT    /staffs/:id(.:format)                    staffs
#update
                          DELETE /staffs/:id(.:format)                    staffs
#destroy
      suggestions_tickets GET    /tickets/suggestions(.:format)           ticket
s#suggestions
      search_form_tickets GET    /tickets/search_form(.:format)           ticket
s#search_form
           search_tickets POST   /tickets/search(.:format)                ticket
s#search
        broadcast_tickets GET    /tickets/broadcast(.:format)             ticket
s#broadcast
             ticket_posts POST   /tickets/:ticket_id/posts(.:format)      posts#
create
         new_ticket_posts GET    /tickets/:ticket_id/posts/new(.:format)  posts#
new
        edit_ticket_posts GET    /tickets/:ticket_id/posts/edit(.:format) posts#
edit
                          GET    /tickets/:ticket_id/posts(.:format)      posts#
show
                          PATCH  /tickets/:ticket_id/posts(.:format)      posts#
update
                          PUT    /tickets/:ticket_id/posts(.:format)      posts#
update
                          DELETE /tickets/:ticket_id/posts(.:format)      posts#
destroy
                  tickets GET    /tickets(.:format)                       ticket
s#index
                          POST   /tickets(.:format)                       ticket
s#create
               new_ticket GET    /tickets/new(.:format)                   ticket
s#new
              edit_ticket GET    /tickets/:id/edit(.:format)              ticket
s#edit
                   ticket GET    /tickets/:id(.:format)                   ticket
s#show
                          PATCH  /tickets/:id(.:format)                   ticket
s#update
                          PUT    /tickets/:id(.:format)                   ticket
s#update
                          DELETE /tickets/:id(.:format)                   ticket
s#destroy
                 pictures GET    /pictures(.:format)                      pictur
es#index
                          POST   /pictures(.:format)                      pictur
es#create
              new_picture GET    /pictures/new(.:format)                  pictur
es#new
             edit_picture GET    /pictures/:id/edit(.:format)             pictur
es#edit
                  picture GET    /pictures/:id(.:format)                  pictur
es#show
                          PATCH  /pictures/:id(.:format)                  pictur
es#update
                          PUT    /pictures/:id(.:format)                  pictur
es#update
                          DELETE /pictures/:id(.:format)                  pictur
es#destroy

问题是路径 / tickets /:ticket_id / posts /:id

1 个答案:

答案 0 :(得分:1)

您已使用resource :posts,请尝试使用resources :posts

对于resourceresources之间的差异,您可以使用此链接。

Difference between resource and resources