Created
June 23, 2009 12:32
-
-
Save kelso/134508 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# potrebujeme uzivatela v pravidelnych intervaloch udrziavat "pri zivote" | |
# musime mu teda niekde aktualizovat cas poslednej aktivity | |
# pomocou before filtra to docielime pri kazdom prekliku aplikaciou | |
# umiestnit do kazdeho controlleru, kde potrebujeme | |
before_filter :do_last_act | |
# application.rb | |
def do_last_act | |
current_user.update_last_activity | |
end | |
# user.rb | |
def update_last_activity | |
self.update_attribute(:last_act, Time.now) | |
end | |
# pozrieme na uzivatelov, ktori nieco robili za poslednych 30 sekund | |
has_many :online_friends, :class_name => 'User', :conditions => ['last_act > ?', 30.seconds.ago] | |
# pouzitie | |
current_user.online_friends |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment