acts_as_commentable_with_threading icon indicating copy to clipboard operation
acts_as_commentable_with_threading copied to clipboard

How to destroy comments?

Open sankalpsingha opened this issue 11 years ago • 3 comments

In your guide, please also specify, how do you destroy comments?

sankalpsingha avatar May 07 '14 13:05 sankalpsingha

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')}

rescribet avatar Jan 22 '15 14:01 rescribet

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

RailsCod3rFuture avatar Aug 18 '17 16:08 RailsCod3rFuture

👌

fakuivan avatar Jul 29 '20 03:07 fakuivan