Skip to content

Instantly share code, notes, and snippets.

@isterin
Created December 14, 2010 19:56
Show Gist options
  • Save isterin/740975 to your computer and use it in GitHub Desktop.
Save isterin/740975 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