2018-05-07 16:47:29 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2017-09-05 22:23:34 +03:00
|
|
|
class PhysicalTicket < ApplicationRecord
|
2017-06-03 16:05:59 +05:30
|
|
|
belongs_to :ticket_purchase
|
|
|
|
|
has_one :ticket, through: :ticket_purchase
|
|
|
|
|
has_one :conference, through: :ticket_purchase
|
|
|
|
|
has_one :user, through: :ticket_purchase
|
2017-07-11 17:05:07 +05:30
|
|
|
has_many :ticket_scannings
|
2017-07-10 20:43:27 +05:30
|
|
|
|
|
|
|
|
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
|
2017-06-03 16:05:59 +05:30
|
|
|
end
|