This post originated from an RSS feed registered with Ruby Buzz
by Robby Russell.
Original Post: Parsing a RSS Feed
Feed Title: Robby on Rails
Feed URL: http://www.contegix.com/rss/feed.xml
Feed Description: My reflections on programming with Ruby, Rails, PostgreSQL... and learning how to run a business...
A friend was asking me how they could easily read a RSS feed and display the last x items in their rails project. This was my quick and dirty response.
require 'rss/2.0'
require 'open-uri'
class RssfeedController < ApplicationController
def index
feed_url = 'http://www.planetrubyonrails.org/xml/rss'
output = "<h1>My RSS Reader</h1>"
open(feed_url) do |http|
response = http.read
result = RSS::Parser.parse(response, false)
output += "Feed Title: #{result.channel.title}<br />"
result.items.each_with_index do |item, i|
output += "#{i+1}. #{item.title}<br />" if i < 10
end
end
render_text output
end
end
Is there an easier way to do this with another RSS library? I figured that the simplest method would be to just use the standard library that comes with Ruby.