title: Calculating Elapsed time in Rails
body: <p>I'm writing an app where I need to compare two :datetime fields and get the difference to display as an "elapsed" time from the start of the record.  I think I have my code right, but I keep getting the below error.  Can someone tell me what I'm doing wrong?</p>
  
  <pre><code>Error on view:
  undefined method `-' for nil:NilClass line 26:
  26:     &lt;td&gt;&lt;%= link_to call.elapsed_time, call %&gt;&lt;/td&gt;
  
  Call.rb (abbreviated)
  before_create :set_dispatched_time
  
  def set_dispatched_time
    self.dispatched_time = Time.now
  end
  
  def elapsed_time
    self.dispatched_time - Time.now
  end
  </code></pre>
  
  <p>My fields in PG are set as :datetime so that I can compute times (I did have them as strings.. ooops) but for some reason it's not calculating.  Do I need to call Time.parse first or something like that?  I'm not really sure which direction to go.  I just want to subtract the dispatched_time field from Time.now</p>