Class: FutureDateValidator

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

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/validators/future_date_validator.rb', line 3

def validate_each(record, attribute, value)
  if value.present?
    begin
      if date = value.to_date
        if date <= Date.today
          record.errors[:embargo_release_date] << "Must be a future date"
        end
      else
        record.errors[:embargo_release_date] << "Invalid Date Format"
      end
    rescue ArgumentError, NoMethodError
      record.errors[:embargo_release_date] << "Invalid Date Format"
    end
  end
end