Parsing a RSS Feed 8
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.
Enjoying the content? Be sure to subscribe to my RSS feed.





blah blah blah. wanna buy some erection cream?
I found this googling for info on the simple-rss gem. Will try to write how I used it on http://ruby.vanhecke.info
Note: For this to work, you need to edit the last part of line 14. (It has an incorrectly encoded less-than sign between
if iand10.Here’s a version you can pop in you lib and call from your pages… cheers
Wow, I’ve been looking for this all day! Thank you!
i’m the type of guy that likes these kind of posts