Class: Just::DateTimePicker::DatabaseAbstraction::Common::JustDateValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/just-datetime-picker/databases/common.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/just-datetime-picker/databases/common.rb', line 8

def validate_each(record, attribute, value)
  return if value.nil?
  return if value.to_s.empty?
  
  begin
    Date.parse(value)
  rescue ArgumentError
    if defined?(Mongoid) and record.class.included_modules.include? Mongoid::Document
      record.errors[attribute] << I18n.t("mongoid.errors.messages.just_datetime_invalid_date")
    else
      record.errors[attribute] << I18n.t("activerecord.errors.messages.just_datetime_invalid_date")
    end
  end
end