Files
kondiplo_front/app/controllers/board_posts_controller.rb

36 lines
1.1 KiB
Ruby
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
class BoardPostsController < ApplicationController
include BoardAccessible
before_action :require_login
before_action :set_game
before_action :set_board
before_action :set_current_participant
def create
# 参加チェック(国選択フェーズでも共通掲示板への投稿を許可)
unless @board.member?(@current_participant) && @game.status.in?(%w[power_selection in_progress])
return redirect_to game_board_path(@game, @board), alert: "投稿権限がありません"
end
@post = @board.board_posts.new(post_params)
@post.participant = @current_participant
# フェーズ情報の付与latest_turnアソシエーションを使用
if @game.latest_turn
@post.phase = @game.latest_turn.phase
end
if @post.save
redirect_to game_board_path(@game, @board) # noticeはチャット的にうるさいので省略
else
redirect_to game_board_path(@game, @board), alert: "投稿に失敗しました"
end
end
private
def post_params
params.require(:board_post).permit(:body)
end
end