title: In ActiveRecord, validate that an attribute is present but may be empty
body: <p>I'm trying to set up my model in Rails 3.2.8 such that particular values must be present, but are allowed to be the empty string. Does anyone know how to do this?</p>
  
  <p>The behavior I'm looking for looks like:</p>
  
  <pre><code>@foo.value = "this is a real value"
  @foo.valid? # =&gt; true
  
  @foo.value = nil
  @foo.valid? # =&gt; false
  
  @foo.value = ""
  @foo.valid? # =&gt; true
  </code></pre>
  
  <p>If I use </p>
  
  <pre><code>validates :foo, :presence =&gt; true
  </code></pre>
  
  <p>then I get what I want for 1 and 2, but not 3. And, helpfully, <code>:allow_blank =&gt; true</code> is <a href="http://guides.rubyonrails.org/active_record_validations_callbacks.html#allow_blank" rel="nofollow">ignored</a> when validating presence.</p>
  
  <p>I also tried</p>
  
  <pre><code>validates :foo, :length =&gt; { :minimum =&gt; 0 }, :allow_nil =&gt; false
  </code></pre>
  
  <p>Same behavior: get what I want for 1 and 2, but not 3.</p>
  
  <p>I suppose I could just mark the column as <code>NOT NULL</code> in the database, but then I have to deal with catching the exception; I'd really rather catch this at the validation stage.</p>
  
  <p>Any ideas?</p>