Sha256: 968349f82d071e077df94fe5e5ac4f0f90d7a965ceb0a36cb28e2faee261ed8a

Contents?: true

Size: 601 Bytes

Versions: 1

Compression:

Stored size: 601 Bytes

Contents

class CommentsController < ApplicationController
  before_action :find_article, only: [:create, :destroy]

  def create
    @comment = @article.comments.create(comment_params.merge(user_id: current_user.id))
    redirect_to article_path(@article)
  end

  def destroy
    @comment = @article.comments.find(params[:id])

    @comment.destroy
    redirect_to article_path(@article), notice: "Comment Destroyed Successfully"
  end

  private

  def comment_params
    params.require(:comment).permit(:commenter, :body)
  end

  def find_article
    @article = Article.find(params[:article_id])
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blog_app-0.0.1 lib/app/controllers/comments_controller.rb