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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "stocks"
  end
  
  def index
    @circuit_regions = CircuitRegion.all

    @circuit_regions = sort_by_sorting(@circuit_regions, "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_regions = @circuit_regions.page(page).per(per_page)
      
      }
    end
  end

  def show
    @circuit_region = CircuitRegion.find(params[:id])

  end

  def new
    @circuit_region = CircuitRegion.new
  
  end

  def edit
    @circuit_region = CircuitRegion.find(params[:id])
    
  end

  def create
    @circuit_region = CircuitRegion.new(params.require(:circuit_region).permit!)

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

  end


  def update
    @circuit_region = CircuitRegion.find(params[:id])


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


  def destroy
    @circuit_region = CircuitRegion.find(params[:id])
    @circuit_region.destroy
    
  end
end
