(t) 514 312 4307 (email) hello@giraffesoft.ca

[FLOSS Week]: timeline_fu: activity feeds made awesome

Posted by: James Golick on 2009-02-20

This release announcement is part of FLOSS week.

If you're working on a webapp these days, chances are you've needed to build an activity feed or two. There are a few approaches floating around — mostly involving observers. Not a fan of observers and needing something reusable, we built our own.

To get started with timeline_fu, run the generator.

script/generate timeline_fu && rake db:migrate

You'll get a model called TimelineEvent and the necessary migration. Then, anywhere you need to fire a timeline event, simply declare it.

class Post
  belongs_to :creator, :class_name => "User"

  fires :created, :actor => :creator,
                  :on    => :create
end

This will fire a TimelineEvent called :created in an after_create callback on the Post model. It's properties will be as follows.

@post = Post.create(:creator => current_user, ...)

@timeline_event.event_type #=> :created
@timeline_event.actor      #=> @post.creator
@timeline_event.subject    #=> @post

Then, to display the timeline_events, you'll need an association on your User model. We've frequently defined this as a has_many :through followed items, like how you might imagine it's implemented in the github activity feed. Then, in your dashboards/show.html.erb, you'd have something like this.

<% @user.timeline_events.each do |e|  -%>
  <%= render :partial => 
    "dashboards/timeline_events/#{e.event_type}", :object => e %>
<% end %>

That's it! Just add fires declarations wherever you need to add something to the activity feed and the necessary templates and you're good to go.

Get It!

$ sudo gem install giraffesoft-timeline_fu

Or fork it on github.

This release announcement is part of FLOSS week. If you're interested in more open source software, consider subscribing or following us on twitter to get the next announcements asap.

blog comments powered by Disqus