Class: BirthdayValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/birthday_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



2
3
4
5
6
# File 'app/validators/birthday_validator.rb', line 2

def validate_each(record, attribute, value)
  return if options[:allow_nil] && value.presence.nil?
  record.errors.add(attribute, :in_past) if !value || value >= Time.now.to_date
  record.errors.add(attribute, :after_1920) if !value || value <= Date.new(1920, 1, 1)
end