28 lines
895 B
Ruby
28 lines
895 B
Ruby
module IdCard
|
|
class ExceptionItem < ApplicationRecord
|
|
belongs_to :exception
|
|
belongs_to :network_logo, optional: true
|
|
belongs_to :provider_section, optional: true
|
|
|
|
validate :only_one_exception_field_present
|
|
|
|
FIELDS_TO_VALIDATE = [:field_value, :card_logo_file_id, :card_provider_id].freeze
|
|
|
|
VALID_FIELD_NAMES = ['network_logo', 'provider_section', 'effective_date']
|
|
|
|
validates :field_name, inclusion: { in: VALID_FIELD_NAMES,
|
|
message: "%{value} is not a valid Id Card Field Name" }
|
|
|
|
|
|
private
|
|
|
|
def only_one_exception_field_present
|
|
present_fields = FIELDS_TO_VALIDATE.count { |field| self[field].present? }
|
|
|
|
if present_fields != 1
|
|
errors.add(:base, "Only one exception field can be present at a time")
|
|
end
|
|
end
|
|
end
|
|
end
|