このコミットが含まれているのは:
@@ -2,6 +2,9 @@ class GekanatorGame < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :guessed_post, class_name: 'Post'
|
||||
belongs_to :correct_post, class_name: 'Post'
|
||||
has_many :question_suggestions,
|
||||
class_name: 'GekanatorQuestionSuggestion',
|
||||
dependent: :delete_all
|
||||
|
||||
validates :answers, presence: true
|
||||
validates :question_count, numericality: { greater_than_or_equal_to: 0 }
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
class GekanatorQuestionSuggestion < ApplicationRecord
|
||||
MAX_QUESTIONS_PER_GAME = 1
|
||||
|
||||
belongs_to :gekanator_game
|
||||
belongs_to :user
|
||||
|
||||
validates :question_text, presence: true, length: { maximum: 1000 }
|
||||
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
|
||||
新しい課題から参照
ユーザをブロックする