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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 23, 4:03 pm, Olivier Bon <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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> Pretty basic I suppose but I''m only a noob! > > Thank you > Oli > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
works a treat! Thank you for your help Oli -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---