diff options
Diffstat (limited to 'users/app/models')
-rw-r--r-- | users/app/models/email.rb | 5 | ||||
-rw-r--r-- | users/app/models/user.rb | 7 |
2 files changed, 8 insertions, 4 deletions
diff --git a/users/app/models/email.rb b/users/app/models/email.rb index 45101c1..4b01838 100644 --- a/users/app/models/email.rb +++ b/users/app/models/email.rb @@ -6,6 +6,11 @@ class Email validates :email, :format => { :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/, :message => "needs to be a valid email address"} + def initialize(attributes = nil, &block) + attributes = {:email => attributes} if attributes.is_a? String + super(attributes, &block) + end + def to_s email end diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 7c9002b..b531dfd 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -113,16 +113,15 @@ class User < CouchRest::Model::Base end def add_email(email) - email = LocalEmail.new({:email => email}) unless email.is_a? Email + email = LocalEmail.new(email) unless email.is_a? Email email_aliases << email end # this currently only adds the first email address submitted. # All the ui needs for now. def email_aliases_attributes=(attrs) - if attrs - email_alias = LocalEmail.new(attrs.values.first) - email_aliases << email_alias + if attrs && attrs.values.first + add_email attrs.values.first end end |