2023-04-03 18:23:49 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Child is a modal for a child of a user
|
|
|
|
class Child < ApplicationRecord
|
|
|
|
belongs_to :user
|
|
|
|
|
|
|
|
validates :first_name, presence: true
|
|
|
|
validates :last_name, presence: true
|
2023-04-04 18:09:17 +02:00
|
|
|
validates :email, presence: true, format: { with: Devise.email_regexp }
|
2023-04-03 18:23:49 +02:00
|
|
|
validate :validate_age
|
|
|
|
|
2023-04-04 18:09:17 +02:00
|
|
|
# birthday should less than 18 years ago
|
2023-04-03 18:23:49 +02:00
|
|
|
def validate_age
|
2023-04-04 18:09:17 +02:00
|
|
|
errors.add(:birthday, I18n.t('.errors.messages.birthday_less_than_18_years_ago')) if birthday.blank? || birthday > 18.years.ago
|
2023-04-03 18:23:49 +02:00
|
|
|
end
|
|
|
|
end
|