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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "tournees"
  end
  
  def index
    @file_tunels = FileTunel.all
    
    @file_tunels = sort_by_sorting(@file_tunels, "created_at DESC")
    
    
    params[:search][:per_page] = params[:search][:per_page] || 50
		per_page = params[:search][:per_page]
		page = (params[:page] and params[:page] != "") ? params[:page] : 1 
		@file_tunels = @file_tunels.page(page).per(per_page)
    

  end

  def show
    @file_tunel = FileTunel.find(params[:id])

  end

  def new
    @file_tunel = FileTunel.new
  
  end

  def edit
    @file_tunel = FileTunel.find(params[:id])
    
  end

  def create
    @file_tunel = FileTunel.new(params.require(:file_tunel).permit!)

    if @file_tunel.save
      redirect_to [:admin, @file_tunel]
    else
      render action: "new"
 
    end

  end


  def update
    @file_tunel = FileTunel.find(params[:id])


    if @file_tunel.update_attributes(params.require(:file_tunel).permit!)
      redirect_to [:admin, @file_tunel]
    else
     render action: "edit" 
      
    end
      
  end


  def destroy
    @file_tunel = FileTunel.find(params[:id])
    @file_tunel.destroy
    
  end
end
