1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-11 22:24:21 +01:00
fab-manager/app/models/child.rb

25 lines
878 B
Ruby
Raw Normal View History

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
has_many :supporting_document_files, as: :supportable, dependent: :destroy
accepts_nested_attributes_for :supporting_document_files, allow_destroy: true, reject_if: :all_blank
has_many :supporting_document_refusals, as: :supportable, dependent: :destroy
2023-04-03 18:23:49 +02:00
validates :first_name, presence: true
validates :last_name, presence: true
# validates :email, presence: true, format: { with: Devise.email_regexp }
validate :validate_age
2023-04-03 18:23:49 +02:00
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-05-29 14:41:30 +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
def full_name
"#{(first_name || '').humanize.titleize} #{(last_name || '').humanize.titleize}"
end
2023-04-03 18:23:49 +02:00
end