Created
March 31, 2015 15:28
-
-
Save fny/dbd3d7d5eb88eb65174b 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 WholeNumberValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
unless value =~ /\A\d+\.0*\z/ | |
record.errors[attribute] << (options[:message] || "must be a whole number") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment