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 http://groups.google.com/group/rubyonrails-talk/browse_frm/thread/12eca4adcddcea9d/b33248819234726f?lnk=gst&q=.empty#b33248819234726f

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:

Tom

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).

vendor/rails/activesupport/lib/active_support/core_ext/blank.rb

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com