Episode 330 · February 3, 2020
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.
Join 29,763+ developers who get early access to new screencasts, articles, guides, updates, and more.