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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "preferences"
  end
  
  def index
    @p_devises = PDevise.all

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

  def show
    @p_devise = PDevise.find(params[:id])

  end

  def new
    @p_devise = PDevise.new
  
  end

  def edit
    @p_devise = PDevise.find(params[:id])
    
  end

  def create
    @p_devise = PDevise.new(params.require(:p_devise).permit!)

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

  end


  def update
    @p_devise = PDevise.find(params[:id])


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


  def destroy
    @p_devise = PDevise.find(params[:id])
    @p_devise.destroy
    
  end
end
