@@ -28,13 +28,10 @@ class Contestant < ApplicationRecord
|
||||
has_and_belongs_to_many :categories
|
||||
|
||||
before_validation :initialize_time_seconds_if_empty
|
||||
before_save :generate_qrcode, if: -> { !qrcode.present? }
|
||||
|
||||
validates :name, presence: true
|
||||
validates :time_seconds, presence: true
|
||||
|
||||
generates_token_for :token
|
||||
|
||||
def form_name
|
||||
if email.present?
|
||||
"#{name} - #{email}"
|
||||
@@ -43,21 +40,9 @@ class Contestant < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def regenerate_qrcode
|
||||
generate_qrcode
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def initialize_time_seconds_if_empty
|
||||
if !self.time_seconds
|
||||
self.time_seconds = 0
|
||||
end
|
||||
end
|
||||
|
||||
def generate_qrcode
|
||||
host = Rails.application.config.action_controller.default_url_options[:host]
|
||||
qrcode = RQRCode::QRCode.new("https://#{host}/public/p/#{self.generate_token_for(:token)}")
|
||||
qrcode = RQRCode::QRCode.new("https://#{host}/public/p/#{self.id}")
|
||||
self.qrcode = qrcode.as_svg(
|
||||
color: "000",
|
||||
shape_rendering: "crispEdges",
|
||||
@@ -67,4 +52,12 @@ class Contestant < ApplicationRecord
|
||||
viewbox: true
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def initialize_time_seconds_if_empty
|
||||
if !self.time_seconds
|
||||
self.time_seconds = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user