How would you create a notification system like on SO or Facebook in RoR?

I'm thinking that notifications would be it's own resource and have a has_many, through relationship with the user model with a join table representing the associations.

A user having many notifications is obvious, and then a notification would have many users because there would be a number of standardized notifications (a commenting notification, a following notification etc.) that would be associated with many users.

Beyond this setup, I'm unsure how to trigger the creation of notifications based on certain events in your application. I'm also a little unsure of how I'd need to set up routing - would it be it's own separate resource or nested in the user resource? I'd find it very helpful if someone could expand on this.

Lastly, ajax polling would likely improve such a feature.

There's probably some things I'm missing, so please fill this out so that it is a good general resource.

44
задан Justin Meltzer 11 April 2011 в 04:00
поделиться