Forum: Ruby on Rails validation + should be > 0

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Petan C. (Guest)
on 2009-02-26 22:07

my default value for variable mainimage_id is 0. I am trying to apply
really basic validation. If mainimage_id is 0 it should fail and if it
is > 0 it should pass the validation.

validates_numericality_of :mainimage_id, :greater_than => 1, :message =>
"Choose image."

This will pass the validation even if the value is 0.
Thanks for your help.

Sarah Mei (Guest)
on 2009-02-26 22:25
(Received via mailing list)
You could try making the default value nil. Makes more sense anyway -
nil indicates lack of data, while 0 suggests there is a default image.

On Thu, Feb 26, 2009 at 12:07 PM, Petan C.
This topic is locked and can not be replied to.