title: If Time Updated At Greater Than X do
body: <p>I think I'm having a brain freeze here but I cannot figure out the best way to do this... Thanks in advance for the help.</p>
  
  <p>I have a some fields in my location table are updated by an external script every 5 minutes. If they're not updated for more than 1 hour, an email will be sent out to the site admins.</p>
  
  <p>That was reasonably straightforward getting a list of dead locations:</p>
  
  <pre><code> scope :not_responding, lambda {
      where('last_heartbeat &lt; ?', Time.now - 1.hour )
    }
  </code></pre>
  
  <p>What I'm stuck on should be very simple.... All I want to do is change the styling of the location name so it's red if it's not responding. </p>
  
  <pre><code>%td
    - @locations.each do |locations|    
      = if ('locations.last_heartbeat &lt; ?', Time.now - 1.hour )  
        red
      -else
        green
  </code></pre>
  
  <p>But that throws an error (unexpected ',')</p>
  
  <p>Can anyone suggest how to move this into my model??</p>
  
  <p>-- UPDATED --</p>
  
  <p>I'm not sure if this is a bug or what but I'm seeing some bizarre results.</p>
  
  <p>Using answer below, I've added this:</p>
  
  <pre><code>def not_responding?
      last_heartbeat &lt; (Time.now - 1.hour)
    end
  </code></pre>
  
  <p>And call using:</p>
  
  <pre><code>- if location.not_responding?
    red
  - else
    green
  </code></pre>
  
  <p>However, this gave me an error about '&lt;' being undefined. </p>
  
  <p>In the end, I had to do this to get it to work. All seems ridiculous....</p>
  
  <pre><code> def not_responding
     last_heartbeat &lt;=&gt; (Time.now - 1.hour)
   end
  </code></pre>
  
  <p>And in the view:</p>
  
  <pre><code>- if (hotspot.not_responding_two == -1)
    red
  - else
    green
  </code></pre>
  
  <p>Does not make sense as the follow test was ok:</p>
  
  <pre><code>def test?
    Time.now &gt; (Time.now - 1.hour)
  end
  </code></pre>