I hacked together a plugin to add a few parameters to
validates_numericality_of based on your needs and my laziness for
explicit
checks.
From the README:
Adds the following parameters:
(plus the messages generated as an error)
:gt => ## “must be greater than ##”
:gte => ## “must be greater than or equal to ##”
:eq => ## “must be equal to ##”
:lt => ## “must be less than ##”
:lte => ## “must be less than or equal to ##”
:odd => ## “must be an odd number”
:even => ## “must be an even number”
:within => ##…## “must be within ## and ##”
After speaking with a buddy of mine also doing Rails, I need to make
some
modifications. It shouldn’t have the :within since this can already be
accomplished with validates_inclusion_of. As far as including in Rails,
it
depends what their definition of numericality is. With the current
function
name, it’s not appropriate to have these extra checks in them and they
really aren’t critical, just saves some code to validate your input.
But my second plugin, once I polish it off should definitely be
included,
but you’ll have to wait for that one