osem-fcy/app/models/physical_ticket.rb
siddhantbajaj 9e154a1dcd Added Token field for physical_ticket
Added token field in physical_ticket model. This token will also be stored in the qr code and will uniqely identify the ticket.
2017-07-24 16:58:36 +05:30

22 lines
481 B
Ruby

class PhysicalTicket < ActiveRecord::Base
belongs_to :ticket_purchase
has_one :ticket, through: :ticket_purchase
has_one :conference, through: :ticket_purchase
has_one :user, through: :ticket_purchase
has_many :ticket_scannings
before_create :set_token
private
def set_token
self.token = generate_token
end
def generate_token
loop do
token = SecureRandom.hex(10)
break token unless PhysicalTicket.exists?(token: token)
end
end
end