1

I am following this guide I have User model.

In ApplicationController:

after_filter :user_activity

private

def user_activity
  current_user.try :touch
end

In User model:

def online?
  updated_at > 10.minutes.ago
end

How can I access all users that are online? I tried in view:

<%= user.online? %>

I got this error:

undefined local variable or method `user'

Some tips ?

Thanks in advance.

Community
  • 1
  • 1
Edgars
  • 913
  • 1
  • 19
  • 53

1 Answers1

2

Call User model <%= User.online %> and make scope instead of method (or static method):

scope :online, where(:updated_at > 10.minutes.ago)

This is an answer actually (except that you should call User.online, not online? which is different method).

Community
  • 1
  • 1
zishe
  • 10,665
  • 12
  • 64
  • 103