class User < ApplicationRecord
validates_with UserBirthZalupaValidator
end
class UserBirthZalupaValidator < ActiveModel::Validator
def validate(record)
begin
birth = Date.parse(record.birth_date.to_s)
record.errors.add(:base, "zlpa") unless birth.between?(start_date, end_date)
rescue StandardError => e
Rails.logger.error("Full zlpa: #{e.inspect}")
end
end
def start_date
Date.new(1900,1,1)
end
def end_date
Time.zone.today
end
end