From 051e61877b4c77a17fd4fa68dfca4d5e74a687df Mon Sep 17 00:00:00 2001 From: tkimia Date: Thu, 3 Apr 2014 17:17:12 -0400 Subject: fixed some of andrews weird stuff with starting a tournament --- app/views/matches/index.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/views/matches/index.html.erb') diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb index 0f86da6..babf45e 100644 --- a/app/views/matches/index.html.erb +++ b/app/views/matches/index.html.erb @@ -1,6 +1,6 @@

<%= @tournament.name %> Matches

- + Date: Thu, 3 Apr 2014 18:03:25 -0400 Subject: matches table is back, and a lot of things are fixed --- app/controllers/tournaments_controller.rb | 9 ++++----- app/models/tournament.rb | 6 +++--- app/views/matches/index.html.erb | 18 +++++++----------- 3 files changed, 14 insertions(+), 19 deletions(-) (limited to 'app/views/matches/index.html.erb') diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 4bba997..ae384c1 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -76,7 +76,7 @@ class TournamentsController < ApplicationController when "join" respond_to do |format| if @tournament.join(current_user) - format.html { render action: 'show', notice: 'You have joined this tournament.' } + 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 } @@ -85,7 +85,7 @@ class TournamentsController < ApplicationController when "leave" respond_to do |format| if @tournament.leave(current_user) - format.html {redirect_to tournaments_url, notice: 'You have left the tournament.' } + 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.' } @@ -94,10 +94,9 @@ class TournamentsController < ApplicationController when "start" @tournament.status = 1 @tournament.save - @tournament.setup() respond_to do |format| if @tournament.setup - format.html { render action: 'show', notice: 'You have joined this tournament.' } + 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 } @@ -105,7 +104,7 @@ class TournamentsController < ApplicationController end else respond_to do |format| - format.html { render action: 'show', notice: "Invalid action", status: :unprocessable_entity } + format.html { redirect_to @tournament, notice: "Invalid action", status: :unprocessable_entity } format.json { render json: @tournament.errors, status: :unprocessable_entity } end end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 6d92f3d..f1d533d 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -26,14 +26,14 @@ class Tournament < ActiveRecord::Base end def setup() - num_teams = (self.players.count/self.max_players_per_team).floor + num_teams = (self.players.count/self.min_players_per_team).floor num_matches = num_teams - 1 for i in 1..num_matches - self.matches.create(name: "Match #{i}") + self.matches.create(name: "Match #{i}", status: 0) end match_num = 0 team_num = 0 - self.players.each_slice(max_players_per_team) do |players| + self.players.each_slice(min_players_per_team) do |players| self.matches[match_num].teams.push(Team.create(users: players)) if (team_num != 0 and team_num % max_teams_per_match == 0) match_num += 1 diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb index babf45e..d4ddb0e 100644 --- a/app/views/matches/index.html.erb +++ b/app/views/matches/index.html.erb @@ -1,28 +1,23 @@ -

<%= @tournament.name %> Matches

+

<%= @tournament.name %> - Matches

- +
- - - - - + <% @tournament.matches.each do |match| %> - - + - + <% end %> @@ -37,7 +32,8 @@ xmlns="http://www.w3.org/2000/svg"> <% (1..@matches.count).each do |i| %> - + + <% end %> -- cgit v1.2.3-54-g00ecf
StatusTournament Name WinnerRemote
<%= match.tournament.id %> <%= match.status %><%= match.tournament %><%= match.id%> <%= match.name %><%= match.winner %><%= link_to "Show", tournament_match_path(@tournament, match) %>