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

class PetitionsController < ApplicationController

  def show
    @petition = Petition.find_by_slug(params[:id])
    @signator = @petition.signators.new(:country => "France")
    @title = "Le Pic Vert - "+@petition.name
  end


  def create
    @signator = PetitionSignator.new(params[:petition_signator])

    @petition = @signator.petition
    @title = "Le Pic Vert - "+@petition.name
    
    if @signator.save
      PetitionMails.confirmation(@signator).deliver
      render action: "create"
    else
      render action: "show"
 
    end

  end


  def confirm
    @signator = PetitionSignator.find_by_token(params[:id])
    @petition = @signator.petition
    @title = "Le Pic Vert - "+@petition.name
    @signator.enabled = true

    @signator.save!
      
  end


end
