diff options
author | guntasgrewal <guntasgrewal@gmail.com> | 2014-04-22 19:13:01 -0400 |
---|---|---|
committer | guntasgrewal <guntasgrewal@gmail.com> | 2014-04-22 19:13:01 -0400 |
commit | 38c2ff9637018d88db7083c76c133da3a72f4c31 (patch) | |
tree | ae5c381e7fe9493abfe8fa6c700df64648246fe2 /app/controllers | |
parent | 3e86ffe1113a096541ea94567bffee79368fb863 (diff) | |
parent | 5c6d6dca48bf3d54f145e859e6d4c8b1befe1f09 (diff) |
Merge branch 'master' of https://github.com/LukeShu/leaguer
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/matches_controller.rb | 11 | ||||
-rw-r--r-- | app/controllers/search_controller.rb | 13 | ||||
-rw-r--r-- | app/controllers/tournaments_controller.rb | 25 |
3 files changed, 32 insertions, 17 deletions
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 59f376a..b50aca5 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -1,6 +1,4 @@ class MatchesController < ApplicationController - before_action :set_tournament, only: [:index, :update] - require 'httparty' require 'json' require 'delayed_job' @@ -118,7 +116,7 @@ class MatchesController < ApplicationController # GET /tournaments/1/matches/1 # GET /tournaments/1/matches/1.json def show - if Tournament.find_by_id(@match.tournament_id).game_id == 1 + if @match.tournament_stage.tournament.game_id == 1 file_blue = "blue.yaml" file_purple = "purple.yaml" @blue2 = YAML.load_file(file_blue) @@ -235,11 +233,8 @@ class MatchesController < ApplicationController private # Use callbacks to share common setup or constraints between actions. def set_match - set_tournament - @match = @tournament.matches.find(params[:id]) - end - def set_tournament - @tournament = Tournament.find(params[:tournament_id]) + @match = Match.find(params[:id]) + @tournament = @match.tournament_stage.tournament end # Never trust parameters from the scary internet, only allow the white list through. diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index ee61487..51aee9e 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -1,2 +1,15 @@ class SearchController < ApplicationController + + def go + @query = params[:query] + + if (@query.nil?) then + return + end + + @tournaments = Tournament.where("name LIKE '%#{@query}%'") + @players = User.where("name LIKE '%#{@query}%'") + + end + end 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 |