title: Rails validation method comparing two fields?
body: <p>My model has two fields that i want to compare to each other as part of the validation. I want to be sure end_time is after start_time. I have written a validation method to compare them, but I must be doing something wrong, because the values are always nil.  Can someone help? </p>
  
  <pre><code>class LogEntry &lt; ActiveRecord::Base
    validates :start_time, :presence =&gt; { :message =&gt; "must be a valid date/time" }
    validates :end_time, :presence =&gt; {:message =&gt; "must be a valid date/time"}
    validate :start_must_be_before_end_time
  
    def start_must_be_before_end_time
      errors.add(:start_time, "must be before end time") unless
         start_time &gt; end_time
    end 
  end
  </code></pre>
  
  <p>gets the error</p>
  
  <pre><code>undefined method `&gt;' for nil:NilClass
  </code></pre>
  
  <p>So, start_time and/or end_time are nil.   I thought I was following the many examples I found, but apparently not. What am I missing? </p>
  
  <p>Thanks.</p>