Forum: Ruby on Rails Best way to handle user's topic views in a forum

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Thibaut.Me (Guest)
on 2008-11-16 18:45
(Received via mailing list)

I'm french... hope you will understand my English ^^

So I'm building a forum for my website from scratch. None of the
already built forum like Beast or RForum suits my needs, and it'll
take as much time to integrate them as to create a new one.

I would like your opinion on how to handle the user's topic views.
The best behavior would be that every unread topic stays in this state
as long as the user doesn't read it, and everytime a new post is
created the topic is marked unread for that specific user. But I think
it'll take to much resources to do that.
So I'm thinking to do it the "punbb" way (not really sure but I
remember it that way) : when a user goes back to the forum, every
topic updated since its last visit is marked unread, until the user
reads it. The only thing I don't like with this approach is that I
need to update an "last_visit_at" attribute on my users every time
they request a page on the forum.
So how would you do it ?

My structure looks like this :

   1. class Forum < ActiveRecord::Base
   2.   has_many :forum_topics
   3.   has_many :forum_posts
   4. end
   6. class ForumTopic < ActiveRecord::Base
   7.   belongs_to :user
   8.   belongs_to :forum
   9.   has_many :forum_posts
  10. end
  12. class ForumPost < ActiveRecord::Base
  13.   belongs_to :user
  14.   belongs_to :forum
  15.   belongs_to :forum_topic
  16. end


Oleksandr B. (Guest)
on 2009-01-26 22:28
take a look at Forulio - Ruby on Rails based forum.
How we did this there.

There is model:

class ReadTopic < ActiveRecord::Base
  belongs_to :user
  belongs_to :topic
  belongs_to :forum

this model store last read post in topic. So when you open topic but did
not look at last post it still stays unread.

You can look live how it works at

and browse code:
This topic is locked and can not be replied to.