Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7792605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:14:13+00:00 2026-06-01T22:14:13+00:00

I think I’m having a brain freeze here but I cannot figure out the

  • 0

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.

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.

That was reasonably straightforward getting a list of dead locations:

 scope :not_responding, lambda {
    where('last_heartbeat < ?', Time.now - 1.hour )
  }

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.

%td
  - @locations.each do |locations|    
    = if ('locations.last_heartbeat < ?', Time.now - 1.hour )  
      red
    -else
      green

But that throws an error (unexpected ‘,’)

Can anyone suggest how to move this into my model??

— UPDATED —

I’m not sure if this is a bug or what but I’m seeing some bizarre results.

Using answer below, I’ve added this:

def not_responding?
    last_heartbeat < (Time.now - 1.hour)
  end

And call using:

- if location.not_responding?
  red
- else
  green

However, this gave me an error about ‘<‘ being undefined.

In the end, I had to do this to get it to work. All seems ridiculous….

 def not_responding
   last_heartbeat <=> (Time.now - 1.hour)
 end

And in the view:

- if (hotspot.not_responding_two == -1)
  red
- else
  green

Does not make sense as the follow test was ok:

def test?
  Time.now > (Time.now - 1.hour)
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:14:15+00:00Added an answer on June 1, 2026 at 10:14 pm

    Probably the easiest way would be something like this:

    class Location < ActiveRecord::Base
      def not_responding?
        last_heartbeat < (Time.now - 1.hour)
      end
    end
    

    I threw in a question mark because this is a Boolean method. And in your view:

    %td
      - @locations.each do |location|    
        -if location.not_responding?
          red
        -else
          green
    

    You need to call a method on the location object, and in this case you’re calling the one we just defined, which will return true or false depending on when the last heartbeat was.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think know how to do this in C# but I'm having syntax trouble
I think I understand the basic principals of T4 but I'm having a hard
I think I already know the answer to this but thought I would ask
I think that asking this might be kind of silly but I'm still wondering
I think this has probably been asked, but after reading a lot, I'm not
I think this is specific to IE 6.0 but... In JavaScript I add a
I think I must be missing something obvious, but I'm unable to find this
I think it's just common sense and Ruby convention to do this but I
Think: tiling my emacs window with eshells, a la xmonad. Is this possible? I
I think I'm burnt out, and that's why I can't see an obvious mistake.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.