Validation null objects and objects with data

I have a model where initially, they we don’t insert an gov_id value
because it isn’t known.

The field is given a value of “” because it is on the form.

I then added code to the ‘create’ method to set that value to nil if it
is blank which seems to be fine but then it fails this validation (if
NULL)

validates_length_of :gov_id, :maximum => 18, :message => “Maximum
18 characters and numbers combined”

seems like I can’t win here…because I can’t pass validation uniqueness
if it is empty ("") and I can’t pass validation length if it is NULL

Suggestions?

Craig

Craig W. wrote:

18 characters and numbers combined"

seems like I can’t win here…because I can’t pass validation uniqueness
if it is empty ("") and I can’t pass validation length if it is NULL

Try validates_length_of :allow_nil …

Ray

On Fri, 2006-03-10 at 12:25 -0800, Ray B. wrote:

validates_length_of :gov_id, :maximum => 18, :message => “Maximum
18 characters and numbers combined”

seems like I can’t win here…because I can’t pass validation uniqueness
if it is empty ("") and I can’t pass validation length if it is NULL

Try validates_length_of :allow_nil …


that didn’t work but
:allow_nil => true
did work

That wasn’t offered in AWDWR book but is in the rails.api

thanks

Craig