1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/app/models/concerns/nameable.rb

22 lines
528 B
Ruby

# frozen_string_literal: true
module Nameable
extend ActiveSupport::Concern
included do
pg_enum :sex, %i[male female]
before_validation :turn_blank_nameable_attributes_into_nils
validates :last_name, presence: true
validates :first_name, presence: true
end
def turn_blank_nameable_attributes_into_nils
%i[
last_name first_name middle_name sex date_of_birth place_of_birth
].each do |attribute|
public_send "#{attribute}=", nil if public_send(attribute).blank?
end
end
end