Simplifying validations a little
This commit is contained in:
parent
05cd57b02c
commit
5f85cf2588
2 changed files with 2 additions and 14 deletions
|
|
@ -22,20 +22,13 @@ class Person
|
|||
key :owner_id, ObjectId
|
||||
|
||||
one :profile, :class_name => 'Profile'
|
||||
validate :profile_is_valid
|
||||
validates_associated :profile
|
||||
before_save :downcase_diaspora_handle
|
||||
|
||||
|
||||
def downcase_diaspora_handle
|
||||
diaspora_handle.downcase!
|
||||
end
|
||||
|
||||
def profile_is_valid
|
||||
if profile.present? && !profile.valid?
|
||||
profile.errors.full_messages.each { |m| errors.add(:base, m) }
|
||||
end
|
||||
end
|
||||
|
||||
many :albums, :class_name => 'Album', :foreign_key => :person_id
|
||||
belongs_to :owner, :class_name => 'User'
|
||||
|
||||
|
|
|
|||
|
|
@ -42,14 +42,9 @@ class User
|
|||
validates_format_of :username, :with => /\A[A-Za-z0-9_.]+\z/
|
||||
validates_presence_of :person, :unless => proc {|user| user.invitation_token.present?}
|
||||
validates_inclusion_of :language, :in => AVAILABLE_LANGUAGE_CODES
|
||||
validates_associated :person
|
||||
|
||||
one :person, :class_name => 'Person', :foreign_key => :owner_id
|
||||
validates_associated :person
|
||||
def person_is_valid
|
||||
if person.present? && !person.valid?
|
||||
person.errors.full_messages.each {|m| errors.add(:base, m)}
|
||||
end
|
||||
end
|
||||
|
||||
many :inviters, :in => :inviter_ids, :class_name => 'User'
|
||||
many :friends, :in => :friend_ids, :class_name => 'Contact'
|
||||
|
|
|
|||
Loading…
Reference in a new issue