Atom Feed Helper
September 23rd, 2007
Action Pack now includes a built in helper to create Atom formatted feeds for resources. (Docs)
In your controller action:
def index
@pages = Page.find(:all, :include => :author)
respond_to do |format|
format.html
format.atom
end
end
In your index.atom.builder file:
atom_feed do |feed|
feed.title "My Entries"
feed.updated @pages.first.created_at
for page in @entries
feed.entry(page) do |entry|
entry.title page.title
entry.content page.body, :type => 'html'
entry.author do |author|
author.name page.author.name
end
end
end
end
Now, the important part of this helper is that if you are passing it a resource to generate a feed for, it can build the links and other elements of the feed implicitly, so you only need to worry about the more important elements like titles and content.
Sorry, comments are closed for this article.