title: How to set the order of validation methods ruby on rails？
body: <p>I am a Ror beginner. There is a model <strong>Lectur</strong>e, I want to validate the format of start time and end time firstly, and then check if the end time is after start time. It works well when the format is valid but once the format is wrong it comes with: undefined method `&lt;' for nil:NilClass. How to makes <em>start_must_be_before_end_time</em>  triggered only when the format is valid? Thanks! </p>
  
  <p>Here is the code:</p>
  
  <pre><code>class Lecture &lt; ActiveRecord::Base
  belongs_to :day
  belongs_to :speaker
  validates :title, :position, presence: true
  
  
  
  validates :start_time, format: { with: /([01][0-9]|2[0-3]):([0-5][0-9])/,
           message: "Incorrect time format" }
  
  
  validates :end_time, format: { with: /([01][0-9]|2[0-3]):([0-5][0-9])/,
          message: "Incorrect time format" }
  
  
  validate :start_must_be_before_end_time
  
  private
  def start_must_be_before_end_time
      errors.add(:end_time, "is before Start time") unless start_time &lt; end_time
  end
  
  end
  </code></pre>