nobosh
2010-Sep-28 03:14 UTC
Implementing a News Feed / Activity Feed on Several Models - Recommendations?
Hello, 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 the group? Gems/Plugins, or experience personally or from others on the best/smartest way to proceed? Thanks! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Sep-28 14:06 UTC
Re: Implementing a News Feed / Activity Feed on Several Models - Recommendations?
http://railscasts.com/episodes/87-generating-rss-feeds -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
hornairs
2010-Sep-28 15:03 UTC
Re: Implementing a News Feed / Activity Feed on Several Models - Recommendations?
I did it by creating a new model called FeedItem and then creating an observer to watch a certain subset of models and create feed items when they were created, updated, and deleted. FeedItems have a polymorphic association to the model being talked about and a user association for who is doing the action, and then a string field denoting the action taken on them ("created" or "destroyed" for example). Then on each model I created a #best_identifier method which allows the model to specify how it should be identified to the user in the feed and elsewhere in the app. So for the feed itself, I just render the last 30 feed items with "#{feed_item.user_id} #{feed_item.action_name} #{feed_item.modified_model.best_identifier} on #{feed_item.created_at.to_s(:short)}". Hopefully this helps! I can pastie my exact code if you''d like. There are some other small tidbits to add like checking for destroyed models (because you can''t call best identifer on them anymore), linking to the model and perhaps user, adding images where appropriate, ... On Sep 27, 11:14 pm, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, 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 the group? Gems/Plugins, or experience > personally or from others on the best/smartest way to proceed? > > Thanks!-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Agoofin
2010-Sep-28 23:52 UTC
Re: Implementing a News Feed / Activity Feed on Several Models - Recommendations?
Nice solution! Another possibility would be to use the before_create and delete methods. Or just have the new controller pull the latest info from your other models by looking at the updated_at field. This way you wouldn''t have to have an extra step when deleting items. On Sep 28, 11:03 am, hornairs <harry.brund...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I did it by creating a new model called FeedItem and then creating an > observer to watch a certain subset of models and create feed items > when they were created, updated, and deleted. FeedItems have a > polymorphic association to the model being talked about and a user > association for who is doing the action, and then a string field > denoting the action taken on them ("created" or "destroyed" for > example). > > Then on each model I created a #best_identifier method which allows > the model to specify how it should be identified to the user in the > feed and elsewhere in the app. So for the feed itself, I just render > the last 30 feed items with "#{feed_item.user_id} > #{feed_item.action_name} #{feed_item.modified_model.best_identifier} > on #{feed_item.created_at.to_s(:short)}". > > Hopefully this helps! I can pastie my exact code if you''d like. There > are some other small tidbits to add like checking for destroyed models > (because you can''t call best identifer on them anymore), linking to > the model and perhaps user, adding images where appropriate, ... > > On Sep 27, 11:14 pm, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > Hello, 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 the group? Gems/Plugins, or experience > > personally or from others on the best/smartest way to proceed? > > > Thanks!-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
nobosh
2010-Sep-29 21:12 UTC
Re: Implementing a News Feed / Activity Feed on Several Models - Recommendations?
@hornairs that''s very interesting. I love the idea of an observer to watch model CRUD actions, I have not heard of such a thing before. Could you show that with pastie, that seems like an elegant way to implement versus after_create... across multiple models. The FeedItems model sounds like it requires a lot of JOINs which is something I want to avoid. I''d like to have everything the feed rendering partial needs in the feedItem record for performance reasons. I''ve seen on StackOverflow an example of doing something like id, model_name, model_type, data {commentID: asdadasd, content: "asdasdad"} What do you think of that? I''m not sure yet how to user a hash that''s stored like that in a column, if you know of any pointers on where I could learn such a thing that''d be great. Thank you On Sep 28, 8:03 am, hornairs <harry.brund...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I did it by creating a new model called FeedItem and then creating an > observer to watch a certain subset of models and create feed items > when they were created, updated, and deleted. FeedItems have a > polymorphic association to the model being talked about and a user > association for who is doing the action, and then a string field > denoting the action taken on them ("created" or "destroyed" for > example). > > Then on each model I created a #best_identifier method which allows > the model to specify how it should be identified to the user in the > feed and elsewhere in the app. So for the feed itself, I just render > the last 30 feed items with "#{feed_item.user_id} > #{feed_item.action_name} #{feed_item.modified_model.best_identifier} > on #{feed_item.created_at.to_s(:short)}". > > Hopefully this helps! I can pastie my exact code if you''d like. There > are some other small tidbits to add like checking for destroyed models > (because you can''t call best identifer on them anymore), linking to > the model and perhaps user, adding images where appropriate, ... > > On Sep 27, 11:14 pm, nobosh <bhellm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hello, 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 the group? Gems/Plugins, or experience > > personally or from others on the best/smartest way to proceed? > > > Thanks!-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.