Class: VouchersController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/vouchers_controller.rb

Instance Method Summary collapse

Instance Method Details

#confirmationObject



12
13
14
# File 'app/controllers/vouchers_controller.rb', line 12

def confirmation
  @user = VoucherUser.new
end

#confirmation_errorObject



65
66
# File 'app/controllers/vouchers_controller.rb', line 65

def confirmation_error
end

#email_sentObject



16
17
18
# File 'app/controllers/vouchers_controller.rb', line 16

def email_sent
  @voucher = Voucher.find(params[:id])
end

#indexObject



3
4
5
# File 'app/controllers/vouchers_controller.rb', line 3

def index
  @vouchers = Voucher.actives
end


54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/vouchers_controller.rb', line 54

def print
  begin
    @voucher = Voucher.find(params[:id])
    @user = VoucherUser.where(voucher_id: @voucher.id).find(params[:user_id])

    render layout: false
  rescue
    render :confirmation_error
  end
end

#send_confirmationObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/vouchers_controller.rb', line 20

def send_confirmation
  @voucher = Voucher.find(params[:id])
  @user = VoucherUser.new(params[:voucher_user])

  if @user.already_required(@voucher)
    if @user.has_confirmed(@voucher)
      render :show, notice: 'Voce ja requisitou este voucher, por favor, aguardo outra promocao'
    else
      render :show, notice: 'Voce ja requisitou este voucher, por favor, acesse seu email para imprimi-lo'
    end
  else
    @voucher.users << @user
    if @voucher.save
      redirect_to :vouchers_email_sent
    else
      render :show, notice: 'Por favor, corrija os erros abaixo'
    end
  end
end

#showObject



7
8
9
10
# File 'app/controllers/vouchers_controller.rb', line 7

def show
  @voucher = Voucher.find(params[:id])
  @user = VoucherUser.new
end