Module: ActiveModel::Validations::HelperMethods

Defined in:
lib/active_model/validations/date_validator.rb

Instance Method Summary collapse

Instance Method Details

#validates_date_of(*attr_names) ⇒ Object

Validates whether the value of the specified attribute is a validate Date

class Person < ActiveRecord::Base
  validates_date_of :payment_date, after: :packaging_date
  validates_date_of :expiration_date, before: Proc.new { Time.now }
end

Configuration options:

  • :after - check that a Date is after the specified one.

  • :before - check that a Date is before the specified one.

  • :after_or_equal_to - check that a Date is after or equal to the specified one.

  • :before_or_equal_to - check that a Date is before or equal to the specified one.

  • :equal_to - check that a Date is equal to the specified one.



126
127
128
# File 'lib/active_model/validations/date_validator.rb', line 126

def validates_date_of(*attr_names)
  validates_with DateValidator, _merge_attributes(attr_names)
end