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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "ventes"
  end
  

  def index
    @p_brut_products = PBrutProduct.order(:name).all

   
  end

  def show
    @p_brut_product = PBrutProduct.find(params[:id])

  end

  def new
    
    
		@p_brut_product = PBrutProduct.new
    

  end

 

  def edit
  
    
    @p_brut_product = PBrutProduct.find(params[:id])
  end

  def create
    @p_brut_product = PBrutProduct.new(params.require(:p_brut_product).permit!)


    if @p_brut_product.save
     @p_brut_products = PBrutProduct.order(:name).all
      
    else
      render action: "new"
 
    end

  end


  def update
    @p_brut_product = PBrutProduct.find(params[:id])


    if @p_brut_product.update_attributes(params.require(:p_brut_product).permit!)
      
       @p_brut_products = PBrutProduct.order(:name).all
    else
     render action: "edit" 
      
    end
      
  end


  def destroy
    @p_brut_product = PBrutProduct.find(params[:id])
    @p_brut_product.destroy
    
    
  end
end
