Class: OmgValidator::Validators::DateValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/omg_validator/validators/date_validator.rb

Overview

Checks whether input is a valid date

validates :posting_date, date: true

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/omg_validator/validators/date_validator.rb', line 7

def validate_each(record, attribute, value)
  return nil if value.nil?
  begin
    Date.parse(value)
  rescue
    record.errors[attribute] = "must be a valid date"
  end
end