24 行
743 B
Ruby
24 行
743 B
Ruby
class GekanatorQuestionSuggestion < ApplicationRecord
|
|
MAX_QUESTIONS_PER_GAME = 1
|
|
ANSWERS = ['yes', 'no', 'partial', 'probably_no', 'unknown'].freeze
|
|
|
|
belongs_to :gekanator_game
|
|
belongs_to :user
|
|
|
|
validates :question_text, presence: true, length: { maximum: 1000 }
|
|
validates :answer, presence: true, inclusion: { in: ANSWERS }
|
|
validates :processed, inclusion: { in: [true, false] }
|
|
validate :question_suggestion_limit_per_game, on: :create
|
|
|
|
private
|
|
|
|
def question_suggestion_limit_per_game
|
|
return if gekanator_game_id.blank?
|
|
|
|
count = GekanatorQuestionSuggestion.where(gekanator_game_id:).count
|
|
if count >= MAX_QUESTIONS_PER_GAME
|
|
errors.add(:base, '質問追加数を超えてゐます.')
|
|
end
|
|
end
|
|
end
|