Quantcast
Channel: How do I make an RSS/Atom feed in Rails 3? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Matt Lennard for How do I make an RSS/Atom feed in Rails 3?

$
0
0

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    endend

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  endend

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


Viewing all articles
Browse latest Browse all 3

Trending Articles