I’m looking for a best practice/standard pattern for generating feeds in Rails 3. Is http://railscasts.com/episodes/87-generating-rss-feeds still valid?
I’m looking for a best practice/standard pattern for generating feeds in Rails 3. Is
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First of all, nowadays I recommend using an ATOM feed instead of RSS.
The specification of ATOM feed offers more value than the RSS one with internationalization, content types and other things and every modern feed reader supports it.
More info about ATOM vs RSS can be found at:
On to the coding:
This example assumes:
NewsItemwith the following attributes:titlecontentauthor_namenews_items_controller.rb), to which you’ll add thefeedactionWe’ll use a builder template for this and the Ruby on Rails atom_feed helper which is of great use.
1. Add the action to the controller
Go to
app/controllers/news_items_controller.rband add:2. Setup your builder template
Now let’s add the template to build the feed.
Go to
app/views/news_items/feed.atom.builderand add:3. Wire it up with a route
Let’s make the feeds available at
http://domain.example/feedThis will call the action with the ATOM format by default and redirect
/feed.rssto/feed.atom.Go to
config/routes.rband add:4. Add the link to ATOM and RSS feeds on the layout
Finally, all that is left is to add the feed to the layout.
Go to
app/views/layouts/application.html.erband add this your<head></head>section: