销毁嵌套注释

时间:2013-11-15 09:27:59

标签: ruby-on-rails nested-attributes

早上好,

我遇到嵌套评论的问题。我有一个部分显示这些,但我想在.each的底部添加一个删除片段。

这是部分:

_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 个答案:

答案 0 :(得分: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 %>
相关问题