All,
I have a field that I’m validating with validates_numericality_of on as
well as validates_inclusion_of, like so:
validates_numericality_of :number_of_owners,
:only_integer => true,
:message => ‘must be a whole number’
validates_inclusion_of :number_of_owners,
:in => 1…3,
:message => ‘should be between 1 and 3’,
:if => Proc.new {|x| x.number_of_owners =~ /\d+/}
As you can see, I’m using the :if clause to limit the inclusion
validation to cases where the field actually contains digits.
But the inclusion valiation never runs. Is this because
x.number_of_owners isn’t set yet at the time the :if is evaluated? How
can I defer the inclusion validation until I know that the numericality
has been satisfied?
Thanks,
Wes