# Validation + should be \> 0

**URL:** <https://www.ruby-forum.com/t/validation-should-be-0/161482>\
**Category:** Rails\
**Created:** [February 26, 2009, 9:07pm UTC](https://www.ruby-forum.com/t/validation-should-be-0/161482 "2009-02-26T21:07:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![petan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c57346/32.png) [@petan](https://www.ruby-forum.com/u/petan)\
**Post date:** [February 26, 2009, 9:07pm UTC](https://www.ruby-forum.com/t/validation-should-be-0/161482/1 "2009-02-26T21:07:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![petan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c57346/32.png) [@petan](https://www.ruby-forum.com/u/petan)\
**Post date:** [February 26, 2009, 9:25pm UTC](https://www.ruby-forum.com/t/validation-should-be-0/161482/2 "2009-02-26T21:25:38Z")

</div>

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.
