Implementing a News Feed / Activity Feed on Several Models - Recommendations?

前端 未结 2 1887
遇见更好的自我
遇见更好的自我 2021-02-03 15:42

I\'m interested in learning how to implement a News Feed / Activity Feed on a web app for multiple models like Books, Authors, Comments, etc...

Any recommendations from

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-03 16:35

    You don't need any Gem.

    1. Create a new model, e.g. Activity, to store activity details. The module should store at least the activity timestamp, the event (e.g. created, destroyed, published, ...) and the id of the related record (you can even use a polymorphic association if you want)
    2. Create a method which gets in input a record with additional metadata and creates a new activity record
    3. In you controllers, call the method each time you want to keep track of an action, passing the modified record as parameter

    Then you'll have a list of Activity records you can easily fetch to display the latest events.

提交回复
热议问题