I have been trying to delete the comments that I have created with acts as commentable gem.
My code :
<%= link_to "×", comment_delete_place_path(comment.id), :method => :delete, :remote => true, :confirm => "Are you sure you want to remove this comment?", :disable_with => "×", :class => 'close' %>
Controller :
def comment_destroy
if params[:comment]
@comment = Comment.find(params[:id])
if @comment.destroy
respond_to do |format|
format.html { redirect_to @place, notice: 'The comment was successfully deleted!'}
format.js
end
end
end
end
Routes :
delete 'places/comment/:id' => 'places#comment_destroy', as: 'comment_delete_place'
It gives me no error but, it does not delete the comment. Where am I going wrong?
In your remote request, there is no comment
parameter (only the id
parameter is provided), so the following line is always false
, you can remove it:
if params[:comment]