掲示板実装
This commit is contained in:
26
app/models/board_post.rb
Normal file
26
app/models/board_post.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
class BoardPost < ApplicationRecord
|
||||
belongs_to :board
|
||||
belongs_to :participant
|
||||
|
||||
validates :body, presence: true
|
||||
|
||||
# 作成後にAction Cableで配信
|
||||
after_create_commit :broadcast_to_board
|
||||
|
||||
private
|
||||
|
||||
def broadcast_to_board
|
||||
# ボードごとのチャンネルに配信
|
||||
ActionCable.server.broadcast(
|
||||
"board_#{board_id}",
|
||||
{
|
||||
post_id: id,
|
||||
participant_id: participant.id,
|
||||
power: participant.power, # 国名
|
||||
body: body,
|
||||
phase: phase, # フェーズ情報
|
||||
created_at: created_at.in_time_zone("Asia/Tokyo").strftime("%Y-%m-%d %H:%M")
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user