refactor: BoardAccessible concernを導入し、ボード関連コントローラを整理、ターン表示ロジックをTurnモデルへ移動し、ボード提案表示をコントローラで処理するよう変更
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
class BoardMembershipsController < ApplicationController
|
||||
include BoardAccessible
|
||||
|
||||
before_action :require_login
|
||||
before_action :set_game
|
||||
before_action :set_board
|
||||
@@ -25,11 +27,6 @@ class BoardMembershipsController < ApplicationController
|
||||
@board.board_memberships.create!(participant_id: target_participant_id, joined_at: Time.current)
|
||||
end
|
||||
|
||||
# メンバー構成が変わったので、他の掲示板と重複していないかチェックが必要だが、
|
||||
# モデルのバリデーションは「作成時」を想定しているため、ここでは簡易チェックに留めるか、
|
||||
# あるいはバリデーションエラーをハンドリングする。
|
||||
# ここではsave成功/失敗で判断
|
||||
|
||||
redirect_to game_board_path(@game, @board), notice: "メンバーを追加しました"
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
redirect_to game_board_path(@game, @board), alert: "メンバー追加に失敗しました: #{e.message}"
|
||||
@@ -49,18 +46,4 @@ class BoardMembershipsController < ApplicationController
|
||||
redirect_to game_board_path(@game, @board), alert: "退出に失敗しました"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_game
|
||||
@game = Game.find(params[:game_id])
|
||||
end
|
||||
|
||||
def set_board
|
||||
@board = @game.boards.find(params[:board_id])
|
||||
end
|
||||
|
||||
def set_current_participant
|
||||
@current_participant = @game.participants.find_by(user: current_user)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user