Forum: Ruby on Rails Help with using RSS parser in a Rails project?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Sharon M. (Guest)
on 2007-05-31 23:22
I'm VERY new at Ruby on Rails. I'm at my first attempt at an application
for myself that will do something useful, thanks in advance for any

I've already written a functioning Ruby script that goes through an RSS
feed to extract and print information I want (headlines and URL for
items published on a certain date). Now I'm trying to turn it into a
Ruby on Rails project (to share with colleagues on an internal server,
and hopefully build on it).

I used Ruby's built-in rss library to parse the feed, with code like


# some of this code adapted from The Ruby Way

i = 0
open(url) do |h|
  resp =
  result = RSS::Parser.parse(resp,false)
    result.items.each do |item|

# I've made a hash with two keys -- the key and the item number

        myhash[["title",i]] = item.title # pulls the headline
        myhash[["pubDate",i]] = item.pubDate # pulls the publish date
        myhash[["link",i]] = # pulls the url

        regex = /articleId=(\d+)/ # uses a regular expression to get the
article ID
        contentid = regex.match(
        myhash[["id",i]] = contentid[1]
        posted = item.pubDate.to_s
        regexp = /[A-Z][a-z][a-z],\s(\d+\s[A-Z][a-z]+\s20\d\d)/
        match = regexp.match(posted)

        if theday == match[1] # checking to see if the publish date
matches the date I want from elsewhere in the script

             print myhash[["id",i]]
             print "  "
             puts myhash[["title",i]]

i = i+1


This all works fine when I run it as a Ruby script from my command line.
But within a Rails project, I get an error message

undefined method `published' for #<RSS::Rss::Channel::Item:0x478c43c>

If I comment out the line with the item.published, then I get

undefined method `url' for #<RSS::Rss::Channel::Item:0x453bac0>

and so on.

Clearly I'm not using the built-in rss library correctly within Rails.
Suggestions to point this beginner on how to do it correctly would be
greatly appreciated!!!
Sharon M. (Guest)
on 2007-06-01 00:32
Oops never mind, I've found my own answer, I needed to use the proper
tags from the RSS feed -- pubDate instead of published, etc. D'oh. No
idea why that was working correctly in the Ruby version!
This topic is locked and can not be replied to.