New on dotherightthing.com: Atom feeds

Posted by # February 13th 03:58 PM

We just went live with a three week tuneup at dotherightthing.com. The main update is the introduction of a wide variety of Atom feeds. I just wrote an in-depth article about all the different feeds available on the dotherighthing.com blog but let me get a bit more geeky here.

We’re using Ruby on Rails and the Simply Restful stuff in it so adding an Atom representation for a resource like entry, company or user is dead simple: just add a new response type with respond_to:

  respond_to do |type|
    type.html do
      # normal stuff
    end
    type.atom do
      # render the atom feed
    end
  end

Now, when someone requests the action with type atom (e.g. http://dotherightthing.com/companies/starbucks.atom), the code inside type.atom will be executed. However, the niceties don’t stop there. The new resource_feeder plugin makes everything even easier. We don’t need to setup a specific template for the feeds at all, all we have to do is to specify some options that don’t match the standard and then call render_atom_feed_for:

  feed_options = { :feed => 
                      {:title => "dotherightthing.com #{params[:sort]} entries",
                       :link => entries_url(:sort => params[:sort])},
                   :item => {:description => :body_html},
                   :class => Entry }

                   ...

  type.atom do
    render_atom_feed_for(@entries, feed_options)
  end

And that’s it!

Another great thing about Simply Restful is that all the url’s are extremely logical. A user profile can be viewed at http://dotherightthing.com/users/jarkko, a feed for his content is at http://dotherightthing.com/users/jarkko.atom. The same is true for companies: http://dotherightthing.com/companies/applehttp://dotherightthing.com/companies/apple.atom.

Gotta love the RESTful features in Rails!

Don’t forget to check out the variety of feeds we offer at dotherightthing.com.

entrepreneurship rails Jump to comment form

Comments

Recently

RailsConf 2007 Speaker

Beginning Ruby on Rails E-Commerce