Save 36% for Black Friday! Save 36% on GoRails for Black Friday! Learn more
Your Teacher
Chris Oliver
Hi, I'm Chris. I'm the creator of GoRails, Hatchbox.io and Jumpstart. I spend my time creating tutorials and tools to help Ruby on Rails developers build apps better and faster.
About This Episode
We can use timestamps in our database to track of online users in your Rails
Notes
Keeping track of users who are "online" in your application can be done in several different ways.
This episode, we're going to implement a simple version of online user tracking by storing a timestamp of the last request the user has made. We can estimate which users are online by simply querying for any users who are online in the last 5 minutes. Depending on how accurate we want to be, we can adjust this window to be 1 minute or 15 minutes to be more or less accurate.
No matter what you do, you'll end up with an estimation here. The user could leave a tab open in their browser for 8 hours and they would be considered "offline" after 5 minutes.
Next episode, we'll talk about using ActionCable and having a websocket provide realtime updates of user's online status.