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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "stocks"
  end
  
  def index
    @p_aromes = PArome.all

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

  def show
    @p_arome = PArome.find(params[:id])

  end

  def new
    @p_arome = PArome.new
  
  end

  def edit
    @p_arome = PArome.find(params[:id])
    
  end

  def create
    @p_arome = PArome.new(params.require(:p_arome).permit!)

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

  end


  def update
    @p_arome = PArome.find(params[:id])


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


  def destroy
    @p_arome = PArome.find(params[:id])
    @p_arome.destroy
    
  end
end
