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,6 +11,14 @@ class Person < ApplicationRecord
11 11
   before_validation :not_admin_if_nil
12 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 22
   private
15 23
   def birth_date_cannot_be_in_future
16 24
     if self.birth_date > Date.today
@@ -23,6 +31,8 @@ class Person < ApplicationRecord
23 31
   end
24 32
 
25 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 37
   end
28 38
 end