Sha256: d5644fb2a2aaf3760399a6ee854af885e0bd54a3a6d6577a50e7e0291fa778cb

Contents?: true

Size: 1.13 KB

Versions: 8

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Admin
  class CategoriesController < Admin::AdminController
    before_action :find_category, only: %i[show edit update destroy]

    def index
      @categories = Category.all
    end

    def show
      redirect_to edit_admin_category_url(@category)
    end

    def new
      @category = Category.new
    end

    def create
      @category = Category.create(category_params)
      if @category.valid?
        flash[:notice] = "New category created"
        redirect_to admin_pages_url(@locale)
      else
        render action: :new
      end
    end

    def edit; end

    def update
      if @category.update(category_params)
        flash[:notice] = "Category was updated"
        redirect_to admin_pages_url(@locale)
      else
        render action: :edit
      end
    end

    def destroy
      @category.destroy
      flash[:notice] = "Category was deleted"
      redirect_to admin_pages_url(@locale)
    end

    protected

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

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pages_core-3.9.2 app/controllers/admin/categories_controller.rb
pages_core-3.9.1 app/controllers/admin/categories_controller.rb
pages_core-3.9.0 app/controllers/admin/categories_controller.rb
pages_core-3.8.3 app/controllers/admin/categories_controller.rb
pages_core-3.8.2 app/controllers/admin/categories_controller.rb
pages_core-3.8.1 app/controllers/admin/categories_controller.rb
pages_core-3.8.0 app/controllers/admin/categories_controller.rb
pages_core-3.7.0 app/controllers/admin/categories_controller.rb