# -*- encoding : utf-8 -*-

class Admin::CircuitRegionCatsController < ApplicationController
  layout "admin"
  before_action :auth_admin

  before_action :admin_space
  
  def admin_space
    @admin_space = "default"
  end
  
  def index
    @circuit_region_cats = CircuitRegionCat.all

    @circuit_region_cats = sort_by_sorting(@circuit_region_cats, "id DESC")
    respond_to do |format|
      format.html{
      
        params[:search][:per_page] = params[:search][:per_page] || 100
        per_page = params[:search][:per_page]
        page = (params[:page] and params[:page] != "") ? params[:page] : 1 
        @circuit_region_cats = @circuit_region_cats.page(page).per(per_page)
      
      }
    end
  end

  def show
    @circuit_region_cat = CircuitRegionCat.find(params[:id])

  end

  def new
    @circuit_region_cat = CircuitRegionCat.new
  
  end

  def edit
    @circuit_region_cat = CircuitRegionCat.find(params[:id])
    
  end

  def create
    @circuit_region_cat = CircuitRegionCat.new(params.require(:circuit_region_cat).permit!)

    if @circuit_region_cat.save
      
    else
      render action: "new"
 
    end

  end


  def update
    @circuit_region_cat = CircuitRegionCat.find(params[:id])


    if @circuit_region_cat.update_attributes(params.require(:circuit_region_cat).permit!)
      
    else
     render action: "edit" 
      
    end
      
  end


  def destroy
    @circuit_region_cat = CircuitRegionCat.find(params[:id])
    @circuit_region_cat.destroy
    
  end
end
