summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/matches_controller.rb2
-rw-r--r--app/models/match.rb2
-rw-r--r--app/models/tournament.rb4
-rw-r--r--app/views/matches/show.html.erb12
4 files changed, 8 insertions, 12 deletions
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb
index 986bb44..1f0d964 100644
--- a/app/controllers/matches_controller.rb
+++ b/app/controllers/matches_controller.rb
@@ -42,7 +42,7 @@ class MatchesController < ApplicationController
def update
respond_to do |format|
if @match.update(match_params)
- format.html { redirect_to @match, notice: 'Match was successfully updated.' }
+ format.html { redirect_to [@tournament, @match], notice: 'Match was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
diff --git a/app/models/match.rb b/app/models/match.rb
index 7dacae5..782dce8 100644
--- a/app/models/match.rb
+++ b/app/models/match.rb
@@ -3,6 +3,6 @@ class Match < ActiveRecord::Base
has_and_belongs_to_many :teams
- belongs_to :winner
+ belongs_to :winner, class_name: "Team"
end
diff --git a/app/models/tournament.rb b/app/models/tournament.rb
index ead9205..79d8b24 100644
--- a/app/models/tournament.rb
+++ b/app/models/tournament.rb
@@ -16,7 +16,7 @@ class Tournament < ActiveRecord::Base
unless joinable_by?(user)
return false
end
- players<<user
+ players.push(user)
end
def setup(tournament)
@@ -28,7 +28,7 @@ class Tournament < ActiveRecord::Base
match_num = 0
team_num = 0
self.players.each_slice(tournament.max_players_per_team) do |players|
- self.matches[match_num].teams[team_num] = Team.new(users: players)
+ self.matches[match_num].teams.push(Team.create(users: players))
if (team_num == 0 and team_num % tournament.max_teams_per_match == 0)
match_num += 1
team_num = 0
diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb
index f5a3686..3a7e7a6 100644
--- a/app/views/matches/show.html.erb
+++ b/app/views/matches/show.html.erb
@@ -8,11 +8,11 @@
<%= @match.name %>
</p>
-<% if @tournament.hosts.include?(current_user) %>
- <%= form_for(@match, method: "put") do |f| %>
+<% if (@tournament.hosts.include?(current_user) and @match.winner.nil?) %>
+ <%= form_for([@tournament, @match], method: "put") do |f| %>
<ul>
<% @match.teams.each do |team| %>
- <li><label><%= f.radio_button(:winner, team.id) %>
+ <li><label><%= f.radio_button(:winner_id, team.id) %>
<%= team.users.collect{|u| u.user_name}.join(", ") %></label></li>
<% end %>
</ul>
@@ -20,15 +20,11 @@
<% end %>
<% end %>
-<%= link_to 'Edit', edit_tournament_match_path(@tournament, @match) %> |
-<%= link_to 'Back', tournament_matches_path %>
-
<% unless @match.winner.nil? %>
<p>
<strong>Winner:</strong>
<%= @match.winner.users.collect{|u| u.user_name}.join(", ") %>
</p>
<% end %>
-<%= link_to 'Edit', edit_match_path(@match) %> |
-<%= link_to 'Back', matches_path %>
+<%= link_to 'Back', tournament_matches_path %>