Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to destroy comments? #69

Open
sankalpsingha opened this issue May 7, 2014 · 3 comments
Open

How to destroy comments? #69

sankalpsingha opened this issue May 7, 2014 · 3 comments

Comments

@sankalpsingha
Copy link

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

@rescribet
Copy link

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
Copy link

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
Copy link

👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants