All threads / How do I publish an RSS feed from my rails app?
Ask A Question


You’re not receiving notifications from this thread.

How do I publish an RSS feed from my rails app?

Stan Smith asked in Rails

I have a simple blog setup with a posts model. Is there a gem that can publish a feed or should I create thus from scratch?

Hey Stan! Like an XML feed of them? If so, it's relatively easy. You've just got to create an index.xml.builder view which will let you render XML.

You can access all the instance variables you need from the controller just like a normal view so you can loop through the posts and print them out in the XML. I believe you'll want the tags and structure mentioned in the following example to conform to what the feeds need for tags.

Basecamp uses this for their feed, for example:

xml.rss("version" => "2.0", "xmlns:dc" => "") do do
    xml.description "Basecamp: Recent items"
    xml.language "en-us"
    xml.ttl "40"

    @recent_items.each do |item|
      xml.item do
        xml.description(item_description(item)) if item_description(item)
        xml.guid(@person.firm.account.url + @recent_items.url(item)) + @recent_items.url(item))

        xml.tag!("dc:creator", item.author_name) if item_has_creator?(item)
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 70,078+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.