elight / acts_as_commentable_with_threading

Similar to acts_as_commentable; however, utilizes awesome_nested_set to provide threaded comments
MIT License
672 stars 167 forks source link

How to destroy comments? #69

Open sankalpsingha opened 10 years ago

sankalpsingha commented 10 years ago

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

rescribet commented 9 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')}
RailsCod3rFuture commented 7 years ago

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
fakuivan commented 4 years ago

👌