Open sankalpsingha opened 10 years ago
It's a basic ActiveRecord model, so in, for example, CommentsController
you can put a destroy
method:
# DELETE /arguments/1/comments/1
def destroy
@comment = Comment.find_by_id params[:id]
authorize @comment, :destroy?
respond_to do |format|
if @comment.destroy
format.html { redirect_to @comment.commentable }
else
format.html { redirect_to @comment.commentable, notice: t('error') }
end
end
end
And link to it:
link_to comment, method: :delete, data: {confirm: t('destroy_confirmation')}
How do you destroy the Comments that relate to a Post when it's destroyed, using AJAX?
def destroy
@post.comments.destroy
respond_to do |format|
format.html { redirect_to post_url, notice: 'Post was successfully destroyed.' }
format.json { head :no_content }
format.js
end
end
👌
In your guide, please also specify, how do you destroy comments?