From b43a801e3ce0ff34b46ea1ea7926635b80e081d1 Mon Sep 17 00:00:00 2001 From: sto Date: Thu, 20 Nov 2025 15:50:50 +0100 Subject: [PATCH] Generate QR codes when not present and asked for --- app/controllers/contestants_controller.rb | 6 ++++++ app/models/contestant.rb | 4 ++++ app/views/contestants/generate_qrcodes.html.slim | 5 +++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/controllers/contestants_controller.rb b/app/controllers/contestants_controller.rb index 4d2cb8d..84d0499 100644 --- a/app/controllers/contestants_controller.rb +++ b/app/controllers/contestants_controller.rb @@ -123,6 +123,12 @@ class ContestantsController < ApplicationController def generate_qrcodes authorize @contest + @contest.contestants.each do |contestant| + if !contestant.qrcode.present? + contestant.public_generate_qrcode + contestant.save + end + end @contestants = @contest.contestants.sort_by { |contestant| contestant.name } end diff --git a/app/models/contestant.rb b/app/models/contestant.rb index 0a895ec..16e3a20 100644 --- a/app/models/contestant.rb +++ b/app/models/contestant.rb @@ -43,6 +43,10 @@ class Contestant < ApplicationRecord end end + def public_generate_qrcode + self.generate_qrcode + end + private def initialize_time_seconds_if_empty diff --git a/app/views/contestants/generate_qrcodes.html.slim b/app/views/contestants/generate_qrcodes.html.slim index e65cfb9..d6ba639 100644 --- a/app/views/contestants/generate_qrcodes.html.slim +++ b/app/views/contestants/generate_qrcodes.html.slim @@ -7,5 +7,6 @@ - if row * 4 + col < @contestants.length .d-flex.flex-column.ms-5 style="align-items: center" = @contestants[row * 4 + col].name - .mt-1 style="width: 200px; height: 200px;" - = @contestants[row * 4 + col].qrcode.html_safe \ No newline at end of file + - if @contestants[row * 4 + col].qrcode.present? + .mt-1 style="width: 200px; height: 200px;" + = @contestants[row * 4 + col].qrcode.html_safe \ No newline at end of file