Shaun Frost Duke Jackson
Shaun Frost Duke Jackson

Reputation: 1266

Destroying Nested Comments

Good Morning,

I'm having an issues with nested comments. I have a partial which shows these but I want to add a delete snippet at the bottom of .each one.

Here is the partial:

_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 %>

Here are my routes:

     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

Here is the stack error, showing no route matches update?

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]

I know it's probably something stupid I'm missing but would really like some help figuring this one out.

Thanks :)

Upvotes: 0

Views: 49

Answers (1)

Debadatt
Debadatt

Reputation: 6015

You are missing book_id . You routes says

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

needs a book_id in path. So need to pass @book object as well in the arguments.

            <%= raw(snippet.content)  %>

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

Upvotes: 1

Related Questions