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

class Admin::<%= controller_class_name %>Controller < ApplicationController
  layout "admin"
  before_action :auth_admin

  before_action :admin_space
  
  def admin_space
    @admin_space = "default"
  end
  
  def index
    @<%= plural_name %> = <%= class_name %>.all

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

  def show
    @<%= singular_name %> = <%= class_name %>.find(params[:id])

  end

  def new
    @<%= singular_name %> = <%= class_name %>.new
  
  end

  def edit
    @<%= singular_name %> = <%= class_name %>.find(params[:id])
    
  end

  def create
    @<%= singular_name %> = <%= class_name %>.new(params.require(:<%= singular_name %>).permit!)

    if @<%= singular_name %>.save
      
    else
      render action: "new"
 
    end

  end


  def update
    @<%= singular_name %> = <%= class_name %>.find(params[:id])


    if @<%= singular_name %>.update_attributes(params.require(:<%= singular_name %>).permit!)
      
    else
     render action: "edit" 
      
    end
      
  end


  def destroy
    @<%= singular_name %> = <%= class_name %>.find(params[:id])
    @<%= singular_name %>.destroy
    
  end
end
