Forums Ruby

Creating ATOM feeds

Subscribe to Creating ATOM feeds 0 post(s), 1 voice

 
Avatar Scott Woods Administrator 41 post(s)

At the last meeting I mentioned that it was really easy to create an ATOM feed for your resources in edge rails. Here’s what I did:

Install the atom_feed_helper:

ruby script/plugin install http://dev.rubyonrails.org/svn/rails/plugins/at...

The README gave me enough info to get started with it, and then I used “curl” on the command line (Mac or Linux) to debug the output by doing, say,

curl http://localhost:3000/comments.atom | less

This would return the XML ATOM feed for all comments (calls the index action). Two things to be noted about that URL:

  1. I’m using RESTful routing here—so instead of the old style /comment/index, we have /comments .
  2. The file extension dictates the format that we’ll get back. Without the ”.atom” on the end of the URL, you’ll get the regular HTML index of comments.

One gotcha that the README example didn’t include: I put my feeds in the same controller as my other code, so my default layout was wrapping the feed. Not good. I had to include a call to “render :layout => false” to prevent that. Here’s the index action from my comments controller:

http://pastie.caboo.se/90108

and here’s app/views/comments/index.atom.builder:

http://pastie.caboo.se/90109

Forums Ruby