summaryrefslogtreecommitdiff
path: root/app/controllers/tournaments_controller.rb
diff options
context:
space:
mode:
authorLuke Shumaker <shumakl@purdue.edu>2014-04-22 18:29:17 -0400
committerLuke Shumaker <shumakl@purdue.edu>2014-04-22 18:29:17 -0400
commitb4bc055585dee532653a8c64e45385e085ec22a8 (patch)
tree6ecad9d0bee5fd547ad0e68ec58bb8fde226e848 /app/controllers/tournaments_controller.rb
parenta185e81094bed6626ac69449eff0f01bdfbc5197 (diff)
I hate code
Diffstat (limited to 'app/controllers/tournaments_controller.rb')
-rw-r--r--app/controllers/tournaments_controller.rb25
1 files changed, 16 insertions, 9 deletions
diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb
index 4b0e1af..03dc5b8 100644
--- a/app/controllers/tournaments_controller.rb
+++ b/app/controllers/tournaments_controller.rb
@@ -95,17 +95,24 @@ class TournamentsController < ApplicationController
end
when "start"
check_permission(:edit, @tournament)
- @tournament.status = 1
- ok =
- @tournament.save &&
- @tournament.tournament_stages.create(scheduling: "elimination") &&
- @tournament.tournament_stages.first.create_matches
respond_to do |format|
- if ok
- format.html { redirect_to @tournament, notice: 'You have started this tournament.' }
- format.json { head :no_content }
+ if @tournament.status == 0
+ @tournament.status = 1
+ success = true
+ ActiveRecord::Base.transaction do
+ success &= @tournament.save &&
+ success &= @tournament.tournament_stages.create(scheduling: "elimination")
+ success &= @tournament.tournament_stages.first.create_matches
+ end
+ if success
+ format.html { redirect_to @tournament, notice: 'You have started this tournament.' }
+ format.json { head :no_content }
+ else
+ format.html { redirect_to @tournament, notice: "You don't have permission to start this tournament." }
+ format.json { render json: "Permission denied", status: :forbidden }
+ end
else
- format.html { redirect_to @tournament, notice: "You don't have permission to start this tournament." }
+ format.html { redirect_to @tournament, notice: "This tournament is not in a state that it can be started." }
format.json { render json: "Permission denied", status: :forbidden }
end
end