Subscribe: Robby on Rails: Parsing a RSS Feed
http://www.robbyonrails.com/xml/atom/article/1599/feed.xml
Added By: Feedage Forager Feedage Grade C rated
Language:
Tags:
blah blah  end  feed  index  length posts  length  open  output  parsing feed  parsing  posts length  posts  response  result  title} 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Robby on Rails: Parsing a RSS Feed

Robby on Rails: Parsing a RSS Feed



thoughts.sort_by{|t| t[:topic]}.collect



Updated: 2006-09-05T22:12:49-05:00

 



Parsing a RSS Feed

2006-09-05T22:12:49-05:00

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 = "

My RSS Reader

" open(feed_url) do |http| response = http.read result = RSS::Parser.parse(response, false) output += "Feed Title: #{result.channel.title}
" result.items.each_with_index do |item, i| output += "#{i+1}. #{item.title}
" 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.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 = "

My RSS Reader

" open(feed_url) do |http| response = http.read result = RSS::Parser.parse(response, false) output += "Feed Title: #{result.channel.title}
" result.items.each_with_index do |item, i| output += "#{i+1}. #{item.title}
" 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. [...]



Comment on Parsing a RSS Feed by Neil Chandler

2010-02-06T07:39:12-06:00

Just a quick update. The last line

posts[0..length – 1] if posts.size > length

will only return posts if the rss returns a number of posts > length otherwise it returns nil

posts.size > length ? posts[0..length – 1] : posts

should be used to return all posts when the total available posts is less the length




Comment on Parsing a RSS Feed by blah

2006-09-05T22:12:50-05:00

blah blah blah. wanna buy some erection cream?