title: Rails: Validating a Date Greater than Another
body: <p>I'm writing a custom validator in ActiveRecord so that a deadline makes sense: </p>
  
  <pre><code>  validate :deadline_is_possible?
  
    def deadline_is_possible?
      if deadline &gt; begins_at
        errors.add(:deadline, 'must be possible')
      end
    end
  </code></pre>
  
  <p>This however generates a "NoMethodError: undefined method `>' for nil:NilClass". I event tried to turn the dates into strings, like: </p>
  
  <pre><code>  def deadline_is_possible?
      if deadline.to_s &gt; begins_at.to_s
        errors.add(:deadline, 'must be possible')
      end
    end
  </code></pre>
  
  <p>and though it doesn't generate an error, doesn't work either. </p>
  
  <p>I also declared other validators (such as </p>
  
  <pre><code>  def begins_at_is_date?
      if !begins_at.is_a?(Date)
        errors.add(:begins_at, 'must be a date')
      end
    end
  </code></pre>
  
  <p>that work OK. </p>