Sha256: be10c936d75f7a15ba53504c9fb1666e821f9c0732d1e0975d41ee44c4bf0e87

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

class ArticlesController < ApplicationController
  def index
    @result = @action.perform
  end

  def show
    @result = @action.perform(params[:id])
  end

  def new
    @input = ArticleInput.new
    @result = @action.perform
  end

  def edit
    @result = @action.perform(params[:id])
    @input = ArticleInput.new(
      title: @result.article.title, body: @result.article.body
    )
  end

  def create
    @input = ArticleInput.new(
      article_params.merge(user_id: session[:user_id])
    )

    @result = @action.perform(@input)

    if @result.success?
      redirect_to(
        article_path(@result.article.id),
        notice: 'Article was successfully created.'
      )
    else
      render(:new)
    end
  end

  def update
    @input = ArticleInput.new(
      article_params.merge(user_id: session[:user_id])
    )

    @result = @action.perform(params[:id], @input)

    if @result.success?
      redirect_to(
        article_path(@result.article.id),
        notice: 'Article was successfully updated.'
      )
    else
      render(:edit)
    end
  end

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

  private

  def article_params
    params.require(:article_input).permit(:title, :body)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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