Tracking online users with timestamps

#330 ยท February 3, 2020

Your Teacher

Hi, I'm Chris. I'm the creator of GoRails, 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


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.


Want to stay up-to-date with Ruby on Rails?

Join 71,933+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.