Files
puzzle-scoreboard/app/models/offline.rb
sto ff5f387a87
Some checks failed
CI / scan_ruby (push) Successful in 20s
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
Offline participation: implement completed puzzle methods
2025-10-31 11:55:28 +01:00

47 lines
1.1 KiB
Ruby

# == Schema Information
#
# Table name: offlines
#
# id :integer not null, primary key
# completed :boolean
# end_time :datetime
# name :string not null
# start_time :datetime not null
# created_at :datetime not null
# updated_at :datetime not null
# contest_id :integer not null
#
# Indexes
#
# index_offlines_on_contest_id (contest_id)
#
# Foreign Keys
#
# contest_id (contest_id => contests.id)
#
class Offline < ApplicationRecord
belongs_to :contest
has_many_attached :images
generates_token_for :token
validates :name, presence: true
validates :start_time, presence: true
validate :end_image_is_present
validate :start_image_is_present
def end_image_is_present
if self.completed && self.images.length < 2
errors.add(:end_image, I18n.t("activerecord.errors.models.offline.attributes.end_image.blank"))
end
end
def start_image_is_present
if !self.images.attached?
errors.add(:images, I18n.t("activerecord.errors.models.offline.attributes.start_image.blank"))
end
end
end