Online or not?

Hey, I'm using this to see who's online on a intranet site at work.

def get_online_users     sessions = CGI::Session::ActiveRecordStore::Session.find(:all, :conditions => ["updated_at >= ?", 30.minutes.ago])     user_ids = sessions.collect{|s| s.data[:user_id]}.compact.uniq     online_users = User.find(user_ids, :select => "screen_name")     return online_users   end

It all works fine and returns a list of who is online at any given time(with 30mins delay)

Now I'd like to show a "online now" badge on the actual user profile, how could I compare this online_user object to see if a given user is present in this online_user object?

Pretty basic I suppose but I'm only a noob!

Thank you Oli

Hey, I'm using this to see who's online on a intranet site at work.

def get_online_users sessions = CGI::Session::ActiveRecordStore::Session.find(:all, :conditions => ["updated_at >= ?", 30.minutes.ago]) user_ids = sessions.collect{|s| s.data[:user_id]}.compact.uniq online_users = User.find(user_ids, :select => "screen_name") return online_users end

It all works fine and returns a list of who is online at any given time(with 30mins delay)

Now I'd like to show a "online now" badge on the actual user profile, how could I compare this online_user object to see if a given user is present in this online_user object?

get_online_users.include?(some_user) (you'll need to make your :select include the id column for this to work)

You could save yourself a database hit (and instantiating a user object for each online user) by having a method that just returns the user_ids. You could then do something like user_ids.include? (some_user.id)

Fred

works a treat! Thank you for your help

Oli