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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "tournees"
  end
  
  def index
    @p_drivers = PDriver.order(:name).all

   
  end

  def show
    @p_driver = PDriver.find(params[:id])

  end

  def new
    
    
		@p_driver = PDriver.new
    

  end

 

  def edit
  
    
    @p_driver = PDriver.find(params[:id])
  end

  def create
    @p_driver = PDriver.new(params.require(:p_driver).permit!)


    if @p_driver.save
     @p_drivers = PDriver.order(:name).all
      
    else
      render action: "new"
 
    end

  end


  def update
    @p_driver = PDriver.find(params[:id])


    if @p_driver.update_attributes(params.require(:p_driver).permit!)
      
       @p_drivers = PDriver.order(:name).all
    else
     render action: "edit" 
      
    end
      
  end


  def destroy
    @p_driver = PDriver.find(params[:id])
    @p_driver.destroy
    
    
  end
end
