Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make an RSS/Atom feed in Rails 3?

I'm pretty new to Rails 3, and I'm trying to make an RSS/Atom feed. I know about auto_discovery_link_tag, but what is the associated controller/action supposed to look like?

Thanks!

like image 852
simonista Avatar asked Oct 16 '10 23:10

simonista


People also ask

Is Atom compatible with RSS?

While many podcasting applications, such as iTunes, support the use of Atom 1.0, RSS 2.0 remains the preferred format.

What is Atom link in RSS feed?

RSS/Atom feeds give good hints about where to find the most recently updated pages. If your website provides an RSS or Atom feed, our crawler will download it to find new links on your site to index first. This is particularly useful when Site Search is doing an incremental update of your website.

How do I use an Atom feed?

To "subscribe" to a site feed, whether RSS or ATOM, you need a feed reader. Simply point the reader to the URL (address) of the site feed, and it will do the rest: it will display the contents of the feed in a window or panel for you. The feed will look like a series of messages.


1 Answers

Auto_discovery_link_tag is a good start. A quick Google search and I found blog posts on How to Create an RSS feed in Rails. Let me fill you in on what your associated controller/action is supposed to look like:

controllers/posts_controller.rb

def feed     @posts = Post.all(:select => "title, author, id, content, posted_at", :order => "posted_at DESC", :limit => 20)       respond_to do |format|       format.html       format.rss { render :layout => false } #index.rss.builder     end end 

The name of this file should match the controller. See, below:

views/posts/feed.rss.builder

xml.instruct! :xml, :version => "1.0"  xml.rss :version => "2.0" do   xml.channel do     xml.title "Your Blog Title"     xml.description "A blog about software and chocolate"     xml.link posts_url      for post in @posts       xml.item do         xml.title post.title         xml.description post.content         xml.pubDate post.posted_at.to_s(:rfc822)         xml.link post_url(post)         xml.guid post_url(post)       end     end   end end 

This is where all the Railsy magic happens. Here, the RSS feed XML is generated and returned to HTTP.

like image 105
Matt Lennard Avatar answered Sep 20 '22 07:09

Matt Lennard