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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "stocks"
  end
  
  def index
    @p_nutris = PNutri.all

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

  def show
    @p_nutri = PNutri.find(params[:id])

  end

  def new
    @p_nutri = PNutri.new
  
  end

  def edit
    @p_nutri = PNutri.find(params[:id])
    
  end

  def create
    @p_nutri = PNutri.new(params.require(:p_nutri).permit!)

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

  end


  def update
    @p_nutri = PNutri.find(params[:id])


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


  def destroy
    @p_nutri = PNutri.find(params[:id])
    @p_nutri.destroy
    
  end
end
