QR codes generation
Some checks failed
CI / scan_ruby (push) Failing after 31s
CI / scan_js (push) Successful in 16s
CI / lint (push) Successful in 16s
CI / test (push) Failing after 45s

This commit is contained in:
sto
2025-11-20 12:01:30 +01:00
parent 3e071f9281
commit 709719b801
16 changed files with 63 additions and 5 deletions

View File

@@ -7,6 +7,7 @@
# email :string
# name :string
# projected_time :string
# qrcode :string
# time_seconds :integer
# created_at :datetime not null
# updated_at :datetime not null
@@ -27,6 +28,7 @@ class Contestant < ApplicationRecord
has_and_belongs_to_many :categories
before_validation :initialize_time_seconds_if_empty
before_commit :generate_qrcode, on: :create
validates :name, presence: true
validates :time_seconds, presence: true
@@ -48,4 +50,17 @@ class Contestant < ApplicationRecord
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)}")
self.qrcode = qrcode.as_svg(
color: "000",
shape_rendering: "crispEdges",
module_size: 3,
standalone: true,
use_path: true,
viewbox: true
)
end
end