Skip to content

Instantly share code, notes, and snippets.

@isterin
Created December 13, 2010 22:50
Show Gist options
  • Save isterin/739740 to your computer and use it in GitHub Desktop.
Save isterin/739740 to your computer and use it in GitHub Desktop.
require 'chronic'
class DateValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
valid = true
begin
y = Chronic.parse(value)
valid = false unless y
rescue
valid = false
end
record.errors[attribute] << (options[:message] || "is not a valid date") unless valid
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment