Use contestant IDs instead of tokens for QR codes
All checks were successful
CI / scan_ruby (push) Successful in 20s
CI / scan_js (push) Successful in 13s
CI / lint (push) Successful in 13s
CI / test (push) Successful in 37s

#6
This commit is contained in:
sto
2025-12-04 10:30:44 +01:00
parent cd41d83429
commit d08370f5f8
4 changed files with 27 additions and 23 deletions

View File

@@ -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