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/passport.rb

34 lines
656 B
Ruby
Raw Normal View History

2018-11-29 20:19:38 -05:00
# frozen_string_literal: true
class Passport < ApplicationRecord
2019-03-25 20:56:31 -04:00
################
# Associations #
################
belongs_to :person, optional: true
2019-07-08 09:40:41 -04:00
has_many :passport_maps,
dependent: :restrict_with_exception
2018-12-02 09:16:16 -05:00
2019-07-08 09:40:41 -04:00
accepts_nested_attributes_for :passport_maps,
reject_if: :blank_passport_map?
2018-12-02 09:41:48 -05:00
2019-03-25 20:56:31 -04:00
###########
# Methods #
###########
2018-12-02 15:29:39 -05:00
def passport_map
passport_maps.order(created_at: :asc).last
end
private
def blank_passport_map?(passport_map_attributes)
passport_map_attributes.all? do |key, value|
next true if key.start_with? 'date_'
value.blank?
end
end
2018-11-29 20:19:38 -05:00
end