Offline participation: implement completed puzzle methods
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
# Table name: offlines
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# completed :boolean
|
||||
# end_time :datetime
|
||||
# name :string not null
|
||||
# start_time :datetime not null
|
||||
@@ -21,20 +22,25 @@
|
||||
class Offline < ApplicationRecord
|
||||
belongs_to :contest
|
||||
|
||||
has_one_attached :start_image
|
||||
has_one_attached :end_image
|
||||
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
|
||||
logger = Logger.new(STDOUT)
|
||||
logger.info "TESTddfzefzef"
|
||||
logger.info self.start_image.attached?
|
||||
if !self.start_image.attached?
|
||||
errors.add(:start_image, I18n.t("activerecord.errors.models.offline.attributes.start_image.blank"))
|
||||
if !self.images.attached?
|
||||
errors.add(:images, I18n.t("activerecord.errors.models.offline.attributes.start_image.blank"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user