ファイル
btrc-hub/backend/app/models/gekanator_game.rb
T
2026-06-08 00:30:20 +09:00

19 行
597 B
Ruby

class GekanatorGame < ApplicationRecord
belongs_to :user, optional: true
belongs_to :guessed_post, class_name: 'Post'
belongs_to :correct_post, class_name: 'Post', optional: true
validates :answers, presence: true
validates :question_count, numericality: { greater_than_or_equal_to: 0 }
validates :won, inclusion: { in: [true, false] }
validate :correct_post_required_when_lost
private
def correct_post_required_when_lost
return if won || correct_post_id.present?
errors.add(:correct_post_id, '外れた時は正解の投稿を指定してくださぃ.')
end
end