Forum: Ruby on Rails validation + should be > 0

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
97bd2f0974055dacf53a0643b013b32e?d=identicon&s=25 Petan Cert (petan)
on 2009-02-26 21:07
Hi,

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.

P.
92497f51734ed56687928d5fd68d870a?d=identicon&s=25 Sarah Mei (Guest)
on 2009-02-26 21: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 Cert
This topic is locked and can not be replied to.