From d3ef9db9e9e695242887c0e4edabf827d255fdd2 Mon Sep 17 00:00:00 2001 From: Ari Timonen Date: Thu, 26 Mar 2020 03:52:13 +0200 Subject: [PATCH] Fix team validation --- app/models/user.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 757d549..5245ec5 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -48,7 +48,7 @@ class User < ActiveRecord::Base attribute :lastvisit, :datetime, default: Time.now.utc - belongs_to :team + belongs_to :team, :optional => true has_one :profile, :dependent => :destroy has_many :bans, :dependent => :destroy has_many :articles, :dependent => :destroy @@ -132,7 +132,6 @@ class User < ActiveRecord::Base validate :validate_team before_create :init_variables - before_save :correct_steamid_universe accepts_nested_attributes_for :profile @@ -292,8 +291,12 @@ class User < ActiveRecord::Base end end + # FIXME: if team has been removed def validate_team if team and !active_teams.exists?({:id => team.id}) + byebug + self.team = nil + self.save! errors.add :team end end