Sha256: 17f80ce031905f68acbc3a90e6d14f9974c06d0f02f904bbcd1634e06c7a9bec

Contents?: true

Size: 1002 Bytes

Versions: 1

Compression:

Stored size: 1002 Bytes

Contents

require_dependency "cas/application_controller"

module Cas
  class Sections::CategoriesController < Sections::ApplicationController
    before_action :set_category, only: [:edit, :update, :destroy]

    def index
      @categories = @section.categories
    end

    def new
      @category = ::Cas::Category.new
    end

    def edit
    end

    def create
      @category = ::Cas::Category.new(category_params)
      @category.section = @section

      if @category.save
        redirect_to section_categories_url(@section), notice: 'Categoria salva com sucesso.'
      else
        render :new
      end
    end

    def update
      if @category.update(category_params)
        redirect_to section_categories_url(@section), notice: 'Categoria salva com sucesso.'
      else
        render :edit
      end
    end

    private

    def set_category
      @category = ::Cas::Category.find(params[:id])
    end

    def category_params
      params.require(:category).permit(:name)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cas-cms-0.1.0 app/controllers/cas/sections/categories_controller.rb