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

class Admin::PetitionsController < ApplicationController
  layout "admin"
  before_filter :authenticate_admin!

  def index
    @petitions = Petition.all

   
  end

  def show
    @petition = Petition.find(params[:id])

  end

  def new
    @petition = Petition.new

  end

  def edit
    @petition = Petition.find(params[:id])
  end

  def create
    @petition = Petition.new(params[:petition])


    if @petition.save
     redirect_to admin_petitions_url, notice: 'La pétition a été crée.' 
      
    else
      render action: "new"
 
    end

  end


  def update
    @petition = Petition.find(params[:id])


    if @petition.update_attributes(params[:petition])
      redirect_to admin_petitions_url, notice: 'Les infos sur la pétition ont été mise à jour.' 
     
    else
     render action: "edit" 
      
    end
      
  end


  def destroy
    @petition = Petition.find(params[:id])
    @petition.destroy
    
    redirect_to admin_petitions_url

  end
end
