validates_... :if option: only validate when not empty?


This basic structure should work. When the value of the :if condition is false, the validation will not run. So perhaps it's the "empty?" method -- should it be "blank?" instead. I tried to find any reference to the differences between blank? empty? nil?. Looking further in the book, it seems that blank? is true if the receiver is nil or an empty string. And there's a thread I found on this group: see

I had trouble finding "blank" documented in the API for ruby or rails, but this could just be because I wasn't looking in the right place :slight_smile:


hmm, just use the option

  :allow_nil => true

Rails (ActiveSupport) defines blank? but doesn't document it (the code has #:nodoc: tags on the methods to keep rdoc from including it).



Rob Biedenharn