Sprankelprachtig aan/afmeldsysteem

person.rb 493B

123456789101112131415161718192021
  1. class Person < ApplicationRecord
  2. validates :email, presence: true, uniqueness: true
  3. validates :first_name, presence: true
  4. validates :last_name, presence: true
  5. validates :is_admin, presence: true
  6. validate :birth_date_cannot_be_in_future
  7. before_validation :not_admin_if_nil
  8. def birth_date_cannot_be_in_future
  9. if self.birth_date > Date.today
  10. errors.add(:birth_date, "can't be in the future.")
  11. end
  12. end
  13. def not_admin_if_nil
  14. self.is_admin ||= false
  15. end
  16. end