summaryrefslogtreecommitdiff
path: root/app/controllers/tournaments_controller.rb
diff options
context:
space:
mode:
authorLuke Shumaker <shumakl@purdue.edu>2014-04-04 20:39:10 -0400
committerLuke Shumaker <shumakl@purdue.edu>2014-04-04 20:39:10 -0400
commitd14dcf9af11a0f2eab2609efb7d9e59a9cc18bb0 (patch)
treebe084eda0796d36dbc846f8257358aeff0cb60f9 /app/controllers/tournaments_controller.rb
parentcb1e09a7ef061cd3c1ca7cf5793d09b2aacb1536 (diff)
re-jigger the TournamentController#update to be all one case block
Diffstat (limited to 'app/controllers/tournaments_controller.rb')
-rw-r--r--app/controllers/tournaments_controller.rb67
1 files changed, 32 insertions, 35 deletions
diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb
index ae384c1..cc25033 100644
--- a/app/controllers/tournaments_controller.rb
+++ b/app/controllers/tournaments_controller.rb
@@ -59,8 +59,8 @@ class TournamentsController < ApplicationController
# PATCH/PUT /tournaments/1
# PATCH/PUT /tournaments/1.json
def update
-
- if params[:update_action].nil?
+ case params[:update_action]
+ when nil
check_perms
respond_to do |format|
if @tournament.update(tournament_params)
@@ -71,42 +71,39 @@ class TournamentsController < ApplicationController
format.json { render json: @tournament.errors, status: :unprocessable_entity }
end
end
- else
- case params[:update_action]
- when "join"
- respond_to do |format|
- if @tournament.join(current_user)
- format.html { redirect_to @tournament, notice: 'You have joined this tournament.' }
- format.json { head :no_content }
- end
- format.html { render action: 'permission_denied', status: :forbidden }
- format.json { render json: "Permission denied", status: :forbidden }
+ when "join"
+ respond_to do |format|
+ if @tournament.join(current_user)
+ format.html { redirect_to @tournament, notice: 'You have joined this tournament.' }
+ format.json { head :no_content }
end
- when "leave"
- respond_to do |format|
- if @tournament.leave(current_user)
- format.html { redirect_to tournaments_url, notice: 'You have left the tournament.' }
- format.json { head :no_content }
- end
- format.html {redirect_to @tournament, notice: 'You were\'t a part of this tournament.' }
- format.json { render json: "Permission denied", status: :forbidden }
- end
- when "start"
- @tournament.status = 1
- @tournament.save
- respond_to do |format|
- if @tournament.setup
- format.html { redirect_to @tournament, notice: 'You have joined this tournament.' }
- format.json { head :no_content }
- end
- format.html { render action: 'permission_denied', status: :forbidden }
- format.json { render json: "Permission denied", status: :forbidden }
+ format.html { render action: 'permission_denied', status: :forbidden }
+ format.json { render json: "Permission denied", status: :forbidden }
+ end
+ when "leave"
+ respond_to do |format|
+ if @tournament.leave(current_user)
+ format.html { redirect_to tournaments_url, notice: 'You have left the tournament.' }
+ format.json { head :no_content }
end
- else
- respond_to do |format|
- format.html { redirect_to @tournament, notice: "Invalid action", status: :unprocessable_entity }
- format.json { render json: @tournament.errors, status: :unprocessable_entity }
+ format.html {redirect_to @tournament, notice: 'You were\'t a part of this tournament.' }
+ format.json { render json: "Permission denied", status: :forbidden }
+ end
+ when "start"
+ @tournament.status = 1
+ @tournament.save
+ respond_to do |format|
+ if @tournament.setup
+ format.html { redirect_to @tournament, notice: 'You have joined this tournament.' }
+ format.json { head :no_content }
end
+ format.html { render action: 'permission_denied', status: :forbidden }
+ format.json { render json: "Permission denied", status: :forbidden }
+ end
+ else
+ respond_to do |format|
+ format.html { redirect_to @tournament, notice: "Invalid action", status: :unprocessable_entity }
+ format.json { render json: @tournament.errors, status: :unprocessable_entity }
end
end
end