Created
October 21, 2015 22:18
-
-
Save gbpereira/aed7c3b8c86f143cc94a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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