summaryrefslogtreecommitdiff
path: root/app/models/tournament.rb
diff options
context:
space:
mode:
authorAndrewMurrell <amurrel@purdue.edu>2014-03-06 22:34:08 -0500
committerAndrewMurrell <amurrel@purdue.edu>2014-03-06 22:34:08 -0500
commit3ce5876375cbb3057ffc96e2886ba57cbd875dc9 (patch)
treee59dc46b293cdcd4ad8ad5b33bd4703f65adb0d9 /app/models/tournament.rb
parentce8b05ed8fa3466c727269daa47ba7df672fdca1 (diff)
parent70bae69d731afc5300ffa5b176732ebe27d0810f (diff)
Fixed some merge errors in show.html.erb
Diffstat (limited to 'app/models/tournament.rb')
-rw-r--r--app/models/tournament.rb20
1 files changed, 16 insertions, 4 deletions
diff --git a/app/models/tournament.rb b/app/models/tournament.rb
index 26dec72..44b22f5 100644
--- a/app/models/tournament.rb
+++ b/app/models/tournament.rb
@@ -1,8 +1,8 @@
class Tournament < ActiveRecord::Base
belongs_to :game
has_many :matches
- has_many :user_tournament_pairs
- has_many :users, :through => :user_tournament_pairs
+ has_and_belongs_to_many :players, class_name: "User", association_foreign_key: "player_id", join_table: "players_tournaments"
+ has_and_belongs_to_many :hosts, class_name: "User", association_foreign_key: "host_id", join_table: "hosts_tournaments"
def open?
return true
@@ -16,7 +16,19 @@ class Tournament < ActiveRecord::Base
unless joinable_by?(user)
return false
end
- pair = UserTournamentPair.new(tournament: self, user: user)
- return pair.save
+ players<<user
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