« kevinpfromnm

Adding an RSS feed.

Posted by kevinpfromnm.

This is mostly the same as standard rails. Hobo does shorten the controller side if you don’t need any filtering.

In your controller, add an index_action for your feed.

index_action :rss

Hobo index actions will paginate for html requests but by default do not for xml requests.

Then add the view file under /app/views/controller/rss.builder

xml.instruct! :xml, :version => "1.0"

xml.rss "version" => "2.0" do
 xml.channel do

   xml.title       "news"
   xml.link        url_for(:only_path => false, :controller => 'posts')
   xml.description "news items"

   @posts.each do |post|
     xml.item do
       xml.title       post.title
       xml.link        url_for(:only_path => false, :controller => 'posts', :action => 'show', :id => post.id)
       xml.description post.body
       xml.updated_at  post.updated_at
       xml.guid        url_for(:only_path => false, :controller => 'posts', :action => 'show', :id => post.id)


The above is from a feed I created for a posts controller. Substitute your fields as needed.

User contributed notes

  • On December 17, 2009 txinto said:

    Hi, I am trying to create a simple rss feed in a subsite, but I got an error. I think the results are coming like an array (not a collection), and I think this method is wrongly trying to paginate them. Is it a bug or must I try to find the way to get them as a collection?



    NoMethodError in OffersController#index

    undefined method `total_pages' for #<Array:0x1051a06e8>

    Application Trace | Framework Trace | Full Trace
    /Library/Ruby/Gems/1.8/gems/will_paginate-2.3.11/lib/will_paginate/view_helpers.rb:197:in `total_pages_for_collection'
    /Library/Ruby/Gems/1.8/gems/will_paginate-2.3.11/lib/will_paginate/view_helpers.rb:98:in `will_paginate'