diff options
author | Aishwarya Subramanian <asubramanian@gitlab.com> | 2019-08-26 21:20:18 +0300 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2019-08-26 21:20:18 +0300 |
commit | a06410d995e1200c7734b2d50e68506320d13dd0 (patch) | |
tree | d8077fbd6de237c020686c2a69533a772d65f8f8 /app/models/user.rb | |
parent | e2251a09bd6f93bdf7734011a2b52b2a43b86799 (diff) |
Using before_save method instead of setter
Removed unused method for name setter method
Diffstat (limited to 'app/models/user.rb')
-rw-r--r-- | app/models/user.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 6131a8dc710..6107aaa7fca 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -161,6 +161,8 @@ class User < ApplicationRecord # # Note: devise :validatable above adds validations for :email and :password validates :name, presence: true, length: { maximum: 128 } + validates :first_name, length: { maximum: 255 } + validates :last_name, length: { maximum: 255 } validates :email, confirmation: true validates :notification_email, presence: true validates :notification_email, devise_email: true, if: ->(user) { user.notification_email != user.email } @@ -881,7 +883,15 @@ class User < ApplicationRecord end def first_name - name.split.first unless name.blank? + read_attribute(:first_name) || begin + name.split(' ').first unless name.blank? + end + end + + def last_name + read_attribute(:last_name) || begin + name.split(' ').drop(1).join(' ') unless name.blank? + end end def projects_limit_left |