Skip to content

Instantly share code, notes, and snippets.

@fny
Created March 31, 2015 15:28
Show Gist options
  • Save fny/dbd3d7d5eb88eb65174b to your computer and use it in GitHub Desktop.
Save fny/dbd3d7d5eb88eb65174b to your computer and use it in GitHub Desktop.
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