Ruby on Rails Wednesday, September 29, 2010

@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...@gmail.com> 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...@gmail.com> 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@googlegroups.com.
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.

No comments:

Post a Comment