Files
kondiplo_front/app/controllers/board_proposals_controller.rb
kontei e90ea88758
Some checks failed
CI / scan_ruby (push) Has been cancelled
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
CI / system-test (push) Has been cancelled
refactor: BoardAccessible concernを導入し、ボード関連コントローラを整理、ターン表示ロジックをTurnモデルへ移動し、ボード提案表示をコントローラで処理するよう変更
2026-02-19 22:46:24 +09:00

51 lines
1.6 KiB
Ruby
Raw 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 BoardProposalsController < 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)
return redirect_to game_board_path(@game, @board), alert: "権限がありません"
end
@proposal = @board.board_proposals.new(proposal_params)
@proposal.proposer = @current_participant
@proposal.status = "pending"
# フェーズ情報の保存latest_turnアソシエーションを使用
latest_turn = @game.latest_turn
@proposal.phase = latest_turn&.phase || "S1901M"
if @proposal.save
redirect_to game_board_path(@game, @board), notice: "提案を作成しました"
else
redirect_to game_board_path(@game, @board), alert: "提案の作成に失敗しました"
end
end
def update
@proposal = @board.board_proposals.find(params[:id])
unless @board.member?(@current_participant)
return redirect_to game_board_path(@game, @board), alert: "権限がありません"
end
new_status = params[:board_proposal][:status]
if %w[accepted rejected].include?(new_status)
@proposal.update!(status: new_status)
redirect_to game_board_path(@game, @board), notice: "提案を#{new_status == 'accepted' ? '承認' : '拒否'}しました"
else
redirect_to game_board_path(@game, @board), alert: "不正なステータスです"
end
end
private
def proposal_params
params.require(:board_proposal).permit(:body)
end
end