Implementing Notifications in Rails

Viewed 7413

In my application, I want to notify a user, when he/she is mentioned in a comment or a post.
The user handle is @user_name, similar to Facebook.
The database table for mentions looks like:

Mention
  mentioned_by: user_id (foreign key)
  user_mentioned: user_id (foreign key)
  comment_id: (foreign key)
  post_id: (foreign key)

I can't figure out a way to implement it though. How do Facebook / Twitter do it?

What I decided to go with, was use ActiveRecord callbacks/ Observer design pattern and whenever a new comment/post is saved to database, I can go through the contents of the post/comment, and look out for any mentions and then execute the notifications as required.

I get the feeling that there are some missing pieces and I am not getting it right.
Is this the best way of doing it?

6 Answers
Related