1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
class Payment < ActiveRecord::Base
validates_presence_of :email, :last_name, :first_name, :payment_gross
validates_as_email :email
belongs_to :team
attr_reader :team_string
def validate
unless team?
t = Team.find_or_initialize_by_name(team_string)
if t.new_record?
t.save
u = User.find_or_initialize_by_email(email)
if u.new_record?
u.first_name = first_name
u.last_name = last_name
u.team_id = t.id
end
t.owner_id = u.id
end
end
end
end
|