From c9f2abad7b9c967e23ed2b2867d426eb27f61387 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 6 Mar 2014 21:29:24 -0500 Subject: make the join tables not have models --- app/controllers/tournaments_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers') diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 346e16b..571203c 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -69,6 +69,6 @@ class TournamentsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def tournament_params - params.require(:tournament).permit(:game_id, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :status) + params.require(:tournament).permit(:game_id, :status, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams) end end -- cgit v1.2.3-54-g00ecf From 2bfc17c39f9b8b5ea71d36d2d5f041295f24192f Mon Sep 17 00:00:00 2001 From: Tomer Kimia Date: Thu, 6 Mar 2014 22:06:32 -0500 Subject: tournaments setup started. NOT FINISHED --- app/controllers/tournaments_controller.rb | 14 ++++++++++---- app/models/tournament.rb | 13 +++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 3f6de26..750a4e7 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -46,8 +46,7 @@ class TournamentsController < ApplicationController # PATCH/PUT /tournaments/1 # PATCH/PUT /tournaments/1.json def update - require 'pp' - pp params + if params[:update_action].nil? check_perms respond_to do |format| @@ -70,8 +69,15 @@ class TournamentsController < ApplicationController format.html { render action: 'permission_denied', status: :forbidden } format.json { render json: "Permission denied", status: :forbidden } end - #when "open" - # TODO + when "open" + respond_to do |format| + if @tournament.setup + format.html { render action: 'show', 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 #when "close" # TODO else diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 26dec72..c359b1c 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -19,4 +19,17 @@ class Tournament < ActiveRecord::Base pair = UserTournamentPair.new(tournament: self, user: user) return pair.save end + + def setup + num_teams = (self.users.count/self.players_per_team).floor + num_matches = num_teams - 1 + for i in 0..num_matches + self.matches.create(name: "Match #{i}") + end + #self.players.each_slice(num_teams) do |team_players| + # Team.new(users: team_players) + #end + end + + end -- cgit v1.2.3-54-g00ecf From 70bae69d731afc5300ffa5b176732ebe27d0810f Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 6 Mar 2014 22:26:37 -0500 Subject: add self as a host to a tourney upon creation --- app/controllers/tournaments_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers') diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 74a1f56..1e26584 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -31,9 +31,9 @@ class TournamentsController < ApplicationController # POST /tournaments.json def create @tournament = Tournament.new(tournament_params) - respond_to do |format| if @tournament.save + @tournament.hosts.push(current_user) format.html { redirect_to @tournament, notice: 'Tournament was successfully created.' } format.json { render action: 'show', status: :created, location: @tournament } else -- cgit v1.2.3-54-g00ecf