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

23 lines
528 B
Ruby
Raw Normal View History

2019-03-26 16:40:53 -04:00
# frozen_string_literal: true
module Nameable
extend ActiveSupport::Concern
included do
2019-07-21 22:42:04 -04:00
pg_enum :sex, %i[male female]
2019-03-26 16:40:53 -04:00
before_validation :turn_blank_nameable_attributes_into_nils
2019-03-26 16:40:53 -04:00
validates :last_name, presence: true
2019-03-26 16:40:53 -04:00
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
2019-03-26 16:40:53 -04:00
end
end