Back to Rails

Oct 20, 2009 14:11

So, I'm doing RoR work again, and I'm hitting those annoying little issues that bugged me the first time around.

Today, it's the fact that I have to setup separate validations to handle nils/blanks. IMO I should be able to do this:

validates_numericality_of :elevation, :allow_nil => false

Now, this works. It validates that elevation is a number ( Read more... )

ruby, rails

Leave a comment

Comments 3

You can use :allow_blank anonymous October 22 2009, 10:02:57 UTC
Try this

validates_numericality_of :elevation, :allow_blank => true

From the api
:allow_blank - If set to true, skips this validation if the attribute is blank (default is false).

Reply


anonymous October 24 2009, 07:19:33 UTC
How about:

validates_presence_of :elevation
validates_numericality_of :elevation, allow_blank => true

Reply

djberg96 October 24 2009, 17:53:37 UTC
Yeah, that'll work. Still feels a bit awkward, but it's definitely better. Thanks!

Reply


Leave a comment

Up