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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "tournees"
  end
  
  def index
    @p_trucks = PTruck.order(:marque).all

   
  end

  def show
    @p_truck = PTruck.find(params[:id])

  end

  def new
    
    
		@p_truck = PTruck.new
    

  end

 

  def edit
  
    
    @p_truck = PTruck.find(params[:id])
  end

  def create
    @p_truck = PTruck.new(params.require(:p_truck).permit!)


    if @p_truck.save
     @p_trucks = PTruck.order(:marque).all
      
    else
      render action: "new"
 
    end

  end


  def update
    @p_truck = PTruck.find(params[:id])


    if @p_truck.update_attributes(params.require(:p_truck).permit!)
      
       @p_trucks = PTruck.order(:marque).all
    else
     render action: "edit" 
      
    end
      
  end


  def destroy
    @p_truck = PTruck.find(params[:id])
    @p_truck.destroy
    
    
  end
end
