I’m done… now what?

5 Oct 2006

You just finished a sprint. Whether it be a single feature, a set of features, or even a release. You were test-driven, user-accepted, and agile, and now you have no juice left. You don’t have the brainpower to start working on the next thing on your task list, but you probably can’t just decide to go home at 2 pm, either. :) So what do you do?

Document what you just did! Assuming, of course, that you weren’t documenting along the way, put everything you know about what you just did in some sort of documentation — whether it’s in a wiki (hi Trac!) or some other documentation repository. Write about it while you can still remember it, and you’ll thank yourself later.



Republish RSS Feeds with Rails

2 Oct 2006

If you’d like to repurpose RSS feeds for display on your site, FeedTools is a great library for fetching and parsing feeds. FeedTools also makes it easy to cache the results of parsing a feed.

In the music store that I’m creating, products can be associated with artists, and those artists often have blogs or other feeds. We can use those feeds to pull info about the artist into the view when displaying a product by the artist. Here’s an example of parsing a feed and displaying the feed items in a view.

The table:

create_table "cached_feeds" do |t|
  t.column "href", :string
  t.column "title", :string
  t.column "link", :string
  t.column "feed_data", :text
  t.column "feed_data_type", :string
  t.column "http_headers", :text
  t.column "last_retrieved", :datetime
end

The helper:

def parse_feed(url)
  return if url.blank?
  FeedTools.configurations[:feed_cache] = "FeedTools::DatabaseFeedCache"
  FeedTools::Feed.open(url)
end

And the view:

< % if @product.artist && feed = parse_feed(@product.artist.feed_url) %>
 

Recent news for < %=h @product.artist.name %>


 

        < % feed.items[0..4].each do |item| %>
         
  • < %= link_to_if item.link, item.title, item.link %> – < %= item.time %>

  •     < % end %>
     

< % end %>

And you’re done. :)