Browse Source

Fix Person creation, add full_name helper

Maarten van den Berg 8 years ago
parent
commit
9dedb4223a
1 changed files with 11 additions and 1 deletions
  1. 11 1
      app/models/person.rb

+ 11 - 1
app/models/person.rb

11
   before_validation :not_admin_if_nil
11
   before_validation :not_admin_if_nil
12
   before_save :update_user_email, if: :email_changed?
12
   before_save :update_user_email, if: :email_changed?
13
 
13
 
14
+  def full_name
15
+    if self.infix
16
+      [self.first_name, self.infix, self.last_name].join(' ')
17
+    else
18
+      [self.first_name, self.last_name].join(' ')
19
+    end
20
+  end
21
+
14
   private
22
   private
15
   def birth_date_cannot_be_in_future
23
   def birth_date_cannot_be_in_future
16
     if self.birth_date > Date.today
24
     if self.birth_date > Date.today
23
   end
31
   end
24
 
32
 
25
   def update_user_email
33
   def update_user_email
26
-    self.user.update!(email: self.email)
34
+    if not self.user.nil?
35
+      self.user.update!(email: self.email)
36
+    end
27
   end
37
   end
28
 end
38
 end