Sha256: 0dabde174f36b216f23b70eedcebd8d2a47af6a8fd600680bb9c7292a3b2a98a

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

# encoding: utf-8

module Admin
  class CategoriesController < Admin::AdminController
    before_action :find_category, only: [: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

3 entries across 3 versions & 1 rubygems

Version Path
pages_core-3.4.3 app/controllers/admin/categories_controller.rb
pages_core-3.5.1 app/controllers/admin/categories_controller.rb
pages_core-3.4.2 app/controllers/admin/categories_controller.rb