I''m working on an app where a "recent activity" feed, much like Basecamp has implimented (screenshot: http://www.basecamphq.com/new-stage/images/basecamp_screenshots/dashboard.gif ) As each model will have different tables, ... how should one go about generating this list in active record efficiently? One thought I have had is generating a view at the DB level, and having a AR model use that view. Jesse
This might be a good area to consider database-level triggers that would aggregate changes into a "recent" table. Or, if you want to implement it in AR, you will probably need to alias all your accessor methods in each model that you want to track to call a "notify" function after execution. Either way, it seems like the record keeping deserves its own table/model. -Jeff Jesse Andrews wrote:>I''m working on an app where a "recent activity" feed, much like >Basecamp has implimented (screenshot: >http://www.basecamphq.com/new-stage/images/basecamp_screenshots/dashboard.gif >) > >As each model will have different tables, ... how should one go about >generating this list in active record efficiently? > >One thought I have had is generating a view at the DB level, and >having a AR model use that view. > >Jesse >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > >-- Jeff Casimir Developer, CommonText Literacy Project: http://www.commontext.com Teacher, César Chávez PCHS: http://www.cesarchavezhs.org
Jesse Andrews wrote:>I''m working on an app where a "recent activity" feed, much like >Basecamp has implimented (screenshot: >http://www.basecamphq.com/new-stage/images/basecamp_screenshots/dashboard.gif >) > >As each model will have different tables, ... how should one go about >generating this list in active record efficiently? > >One thought I have had is generating a view at the DB level, and >having a AR model use that view. > >Jesse >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > >How about defining a "find_recent" method in your classes? Assumes you have something like a create date or update date to sort on: MyClass < ActiveRecord::Base def sort_field ''create_date desc'' end def find_recent(limit = 10 find(:all, :order => sort_field, :limit => limit) end end
Heh, i''m sure you will get the wildest responses. Like stored procedures, views and triggers. Its incredibly easy to implement. All you need is a table which takes user_id and a string and records a created_at. Now you create a observer which observes all the models and their events which you want to add to this list and in a before_filter you feed the current user to a cattr_accessor of this observer. Now you just create a big fat case and happily create new event log entries when something happens which interests you. On 8/7/05, Jesse Andrews <anotherjesse-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m working on an app where a "recent activity" feed, much like > Basecamp has implimented (screenshot: > http://www.basecamphq.com/new-stage/images/basecamp_screenshots/dashboard.gif > ) > > As each model will have different tables, ... how should one go about > generating this list in active record efficiently? > > One thought I have had is generating a view at the DB level, and > having a AR model use that view. > > Jesse > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Tobi http://www.snowdevil.ca - Snowboards that don''t suck http://typo.leetsoft.com - Open source weblog engine http://blog.leetsoft.com - Technical weblog
On 8/8/05, Tobias Luetke <tobias.luetke-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Heh, i''m sure you will get the wildest responses. Like stored > procedures, views and triggers.What about web services? BPEL? JMS based messaging to a cluster of .... [slap]> Its incredibly easy to implement....> Now you just create a big fat case and happily create new event log > entries when something happens which interests you.This is very much the rails way of doing things. It does what you need, with minimal code, and slays some sacred cows in the process. -- Cheers Koz
> > >>Its incredibly easy to implement. >> >> >... > > >>Now you just create a big fat case and happily create new event log >>entries when something happens which interests you. >> >> > >This is very much the rails way of doing things. It does what you >need, with minimal code, and slays some sacred cows in the process. > > >Or a filter that runs (after I suppose) each action and records the activity in the appropriate table - I suppose this could be a big fat case, but logging of this form is basically one of teh main reasons AOP was invented, and filters are a decent halfway house to full AOP so why not use them? my 2 vnd (very little :) Kev