掲示板実装
This commit is contained in:
@@ -2,6 +2,8 @@ class Game < ApplicationRecord
|
||||
has_many :turns, dependent: :destroy
|
||||
has_many :participants, dependent: :destroy
|
||||
has_many :users, through: :participants
|
||||
has_many :boards, dependent: :destroy
|
||||
has_one :latest_turn, -> { order(number: :desc) }, class_name: "Turn"
|
||||
|
||||
# パスワード保護
|
||||
has_secure_password :password, validations: false
|
||||
@@ -26,6 +28,9 @@ class Game < ApplicationRecord
|
||||
# ターンスケジュールバリデーション
|
||||
validate :validate_turn_schedule
|
||||
|
||||
# コールバック
|
||||
after_create :create_global_board
|
||||
|
||||
# ヘルパーメソッド
|
||||
def password_protected?
|
||||
password_digest.present?
|
||||
@@ -162,4 +167,8 @@ class Game < ApplicationRecord
|
||||
errors.add(:turn_schedule, "は0〜23の数値をカンマ区切りで入力してください(例: 0,18)")
|
||||
end
|
||||
end
|
||||
|
||||
def create_global_board
|
||||
boards.create!(board_type: "global", is_public: true)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user