Skip to content

Instantly share code, notes, and snippets.

@gbpereira
Created October 21, 2015 22:18
Show Gist options
  • Save gbpereira/aed7c3b8c86f143cc94a to your computer and use it in GitHub Desktop.
Save gbpereira/aed7c3b8c86f143cc94a to your computer and use it in GitHub Desktop.
class DateValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
valid = value.to_date rescue false
record.errors[attribute] << (
options[:message] || "invalid date"
) unless valid
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment