2013-11-15 72 views
0

早上好,銷燬嵌套註釋

我遇到了嵌套註釋問題。我有一個顯示這些的部分,但我想在每個底部添加一個刪除片段。

下面是部分:

_snippets.html.erb

<% @snippets.each do |snippet| %> 


       <%= raw(snippet.content) %> 

       <% if can? :manage, snippet %> 
       <%= link_to 'delete', book_snippet_path(snippet), :method => :delete %> 
       <% end %> 



<% end %> 

這裏是我的路線:

 book_snippets POST  /books/:book_id/snippets(.:format)   snippets#create 
    edit_book_snippet GET  /books/:book_id/snippets/:id/edit(.:format) snippets#edit 
     book_snippet PATCH /books/:book_id/snippets/:id(.:format)  snippets#update 
        PUT  /books/:book_id/snippets/:id(.:format)  snippets#update 
        DELETE /books/:book_id/snippets/:id(.:format)  snippets#destroy 

這裏是堆棧錯誤,表示沒有路徑相符更新?

No route matches {:action=>"update", :controller=>"snippets", :id=>nil, :book_id=>#<Snippet id: 4, content: "<p>YACHT!</p>\r\n", book_id: 4, created_at: "2013-11-15 09:12:20", updated_at: "2013-11-15 09:12:25", approved: true, user_id: 1>, :format=>nil} missing required keys: [:id] 

我知道這可能是一些愚蠢的我失蹤,但真的想一些幫助搞清楚這一個。

謝謝:)

回答

1

你缺少book_id。你的路線說

DELETE /books/:book_id/snippets/:id(.:format) 

需要一個book_id的路徑。所以還需要在參數中傳遞@book對象。

  <%= raw(snippet.content) %> 

      <% if can? :manage, snippet %> 
      <%= link_to 'delete', book_snippet_path(@book, snippet), :method => :delete %> 
      <% end %> 
+0

我知道這是一些愚蠢的我失蹤。我認爲你必須始終使用嵌套評論來傳遞對象。如果利益有DRYer的方式來做到這一點? –