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

class Admin::TinyUrlsController < ApplicationController
  layout "admin"
  before_action :auth_admin
  
  def index
    @tiny_urls = TinyUrl.all
  end

  def new
    @tiny_url = TinyUrl.new
  end

  def edit
    @tiny_url = TinyUrl.find(params[:id])
  end

  def create
    @tiny_url = TinyUrl.new(params.require(:tiny_url).permit!)

 
    if @tiny_url.save
      redirect_to admin_tiny_urls_url, notice: 'Url courte crée.' 
      
    else
      render action: "new" 
 
    end

  end

  def update
    @tiny_url = TinyUrl.find(params[:id])

   
    if @tiny_url.update_attributes(params.require(:tiny_url).permit!)
      redirect_to admin_tiny_urls_url, notice: 'Url courte modifiée.' 
     
    else
      render action: "edit" 
      
    end
    
  end

 
  def destroy
    @tiny_url = TinyUrl.find(params[:id])
    @tiny_url.destroy

     redirect_to admin_tiny_urls_url, :notice => "Url courte supprimée."
  end
end
