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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "default"
  end
  
  def index
    @p_product_ref_specs = PProductRefSpec.all

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

  def show
    @p_product_ref_spec = PProductRefSpec.find(params[:id])

  end

  def new
    @p_product_ref_spec = PProductRefSpec.new
    @p_product_ref_spec.build_p_spec_type
    @p_product_ref_spec.build_p_spec_value

  end

  def edit
    @p_product_ref_spec = PProductRefSpec.find(params[:id])
    
  end

  def create
    @p_product_ref_spec = PProductRefSpec.new(params.require(:p_product_ref_spec).permit!)

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

  end


  def update
    @p_product_ref_spec = PProductRefSpec.find(params[:id])


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


  def destroy
    @p_product_ref_spec = PProductRefSpec.find(params[:id])
    @p_product_ref_spec.destroy
    
  end
end
