Sha256: 868c93e74d915d5b924e31a1cd9287b21ac1ea805420c8c63b15c7bd162a0ed0

Contents?: true

Size: 1.5 KB

Versions: 28

Compression:

Stored size: 1.5 KB

Contents

class VouchersController < ApplicationController

  def index
    @vouchers = Voucher.actives
  end

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

  def confirmation
    @user = VoucherUser.new
  end

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

  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

  def confirmation
    begin
      voucher = Voucher.find(params[:id])
      user = VoucherUser.where(voucher_id: voucher.id).find(params[:user_id])
      user.confirmed = true
      user.confirmation_date = Time.now
      user.save

      redirect_to vouchers_print_path
    rescue
      render :confirmation_error
    end
  end

  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

  def confirmation_error
  end

end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
mix-rails-0.25.1 mix-rails-vouchers/app/controllers/vouchers_controller.rb
mix-rails-vouchers-0.25.1 app/controllers/vouchers_controller.rb
mix-rails-0.25.0 mix-rails-vouchers/app/controllers/vouchers_controller.rb
mix-rails-vouchers-0.25.0 app/controllers/vouchers_controller.rb
mix-rails-0.24.1 mix-rails-vouchers/app/controllers/vouchers_controller.rb
mix-rails-vouchers-0.24.1 app/controllers/vouchers_controller.rb
mix-rails-0.24.0 mix-rails-vouchers/app/controllers/vouchers_controller.rb
mix-rails-vouchers-0.24.0 app/controllers/vouchers_controller.rb
mix-rails-0.23.1 mix-rails-vouchers/app/controllers/vouchers_controller.rb
mix-rails-vouchers-0.23.1 app/controllers/vouchers_controller.rb
mix-rails-0.23.0 mix-rails-vouchers/app/controllers/vouchers_controller.rb
mix-rails-vouchers-0.23.0 app/controllers/vouchers_controller.rb
mix-rails-0.22.0 mix-rails-vouchers/app/controllers/vouchers_controller.rb
mix-rails-vouchers-0.22.0 app/controllers/vouchers_controller.rb
mix-rails-0.16.0 mix-rails-vouchers/app/controllers/vouchers_controller.rb
mix-rails-vouchers-0.16.0 app/controllers/vouchers_controller.rb
mix-rails-0.15.0 mix-rails-vouchers/app/controllers/vouchers_controller.rb
mix-rails-vouchers-0.15.0 app/controllers/vouchers_controller.rb
mix-rails-0.12.2 mix-rails-vouchers/app/controllers/vouchers_controller.rb
mix-rails-vouchers-0.12.2 app/controllers/vouchers_controller.rb