diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-03-06 20:37:53 -0500 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-03-06 20:37:53 -0500 |
commit | 7bcd854443e368806cf1f4ece562c157db723d1a (patch) | |
tree | 853ce7d9a5a45ca678daf5a50be4c70f1bd66837 /app/models | |
parent | a1700f50ee800cfbfb93bd7dfff7b5d79ae2cb2f (diff) |
fix joining a tournament
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/tournament.rb | 7 | ||||
-rw-r--r-- | app/models/user.rb | 3 |
2 files changed, 6 insertions, 4 deletions
diff --git a/app/models/tournament.rb b/app/models/tournament.rb index ca7fade..26dec72 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -1,7 +1,8 @@ class Tournament < ActiveRecord::Base belongs_to :game has_many :matches - has_many :users, :through => :user_tournament_pair + has_many :user_tournament_pairs + has_many :users, :through => :user_tournament_pairs def open? return true @@ -12,10 +13,10 @@ class Tournament < ActiveRecord::Base end def join(user) - unless joinable?(user) + unless joinable_by?(user) return false end - pair = new_user_tournament_pair(user: user) + pair = UserTournamentPair.new(tournament: self, user: user) return pair.save end end diff --git a/app/models/user.rb b/app/models/user.rb index 6405c8e..bad7f7b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,6 @@ class User < ActiveRecord::Base - has_many :tournaments, :through => :user_tournament_pair + has_many :user_tournament_pairs + has_many :tournaments, :through => :user_tournament_pairs before_save { self.email = email.downcase } before_save { self.user_name = user_name } |