Sha256: 91ab6870139495821bfa8470c51199cf0d6f89bf1fac324415b9c6a84bea1a16

Contents?: true

Size: 878 Bytes

Versions: 3

Compression:

Stored size: 878 Bytes

Contents

# frozen_string_literal: true

class CommentsController < ApplicationController
  def new
    @input = CommentInput.new(article_id: params[:article_id])
    @result = @action.perform
  end

  def create
    @input = CommentInput.new(
      comment_params.merge(article_id: params[:article_id],
user_id: session[:user_id])
    )

    @result = @action.perform(@input)

    if @result.success?
      redirect_to(
        article_path(@result.comment.article_id),
        notice: 'Comment was successfully created.'
      )
    else
      render(:new)
    end
  end

  def destroy
    @action.perform(params[:id])
    redirect_to(
      article_path(params[:article_id]),
      notice: 'Comment was successfully destroyed.'
    )
  end

  private

  # Only allow a list of trusted parameters through.
  def comment_params
    params.require(:comment_input).permit(:body)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
upgrow-0.0.5 test/dummy/app/controllers/comments_controller.rb
upgrow-0.0.4 test/dummy/app/controllers/comments_controller.rb
upgrow-0.0.3 test/dummy/app/controllers/comments_controller.rb