2013-11-15 143 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的方式来做到这一点? –