Reputation: 2170
I have a nested resource, comments like so....
resources :microposts do
member do
get :upvote, :undo_upvote
end
member do
get :follow, :unfollow
end
resources :responses do
member do
get :upvote, :undo_upvote
end
resources :comments
end
end
I have a delete button on the comments index page....
<div class = "Comment" id="comment-<%= comment.id %>">
<%= link_to comment_avatar_for(comment.user), comment.user %>
<span class="Commentator">
<%= comment.user.full_name %>
</span>
<span class="content">
<%= comment.body %>
</span>
<span class="timestamp">
Posted <%= time_ago_in_words(comment.created_at) %> ago.
</span>
<span class="timestamp">
<% if current_user?(comment.user) %>
<%= link_to "delete", comment, method: :delete, data: { confirm: "You sure?" }, :class => "btn btn-default btn-xs delete" %>
<% end %>
</span>
</div>
And I am getting this error when I load the page
undefined method `comment_path' for #<# <Class:0x007f8936876e70>:0x007f8931857020>
I am uncertain why this isn't working - after all I have the correct instance of 'comment'. If someone could just point me in the right direction I would be grateful.
Upvotes: 0
Views: 297
Reputation: 10406
Rails makes assumptions.
Because you have an instance of Comment
it assumes you're going to be using comment_path
, but you don't have that as per your routes so you need to set the correct path:
<%= link_to "delete", micropost_response_comment_path(@micropost, @response, comment), method: :delete, data: { confirm: "You sure?" }, :class => "btn btn-default btn-xs delete" %>
I might have the path wrong, but hopefully you get the idea.
Upvotes: 1