# Help with using RSS parser in a Rails project?

**URL:** <https://www.ruby-forum.com/t/help-with-using-rss-parser-in-a-rails-project/105629>\
**Category:** Rails\
**Created:** [May 31, 2007, 9:22pm UTC](https://www.ruby-forum.com/t/help-with-using-rss-parser-in-a-rails-project/105629 "2007-05-31T21:22:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sharon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/67e7ee/32.png) [@sharon](https://www.ruby-forum.com/u/sharon)\
**Post date:** [May 31, 2007, 9:22pm UTC](https://www.ruby-forum.com/t/help-with-using-rss-parser-in-a-rails-project/105629/1 "2007-05-31T21:22:49Z")

</div>

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  
advice!

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  
this:

> > > > > > > > > > > >

# some of this code adapted from The Ruby Way

i = 0  
open(url) do |h|  
resp = h.read  
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]] = item.link # pulls the url

    regex = /articleId=(\d+)/ # uses a regular expression to get the

```

article ID  
contentid = regex.match(item.link)  
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]]
         posted_array.push(myhash[["id",i]])
       end

```

i = i+1  
end

end  
\<\<\<\<\<\<\<\<\<\<\<

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!!!

---

<div class="post-metadata">

**Author:** ![sharon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/67e7ee/32.png) [@sharon](https://www.ruby-forum.com/u/sharon)\
**Post date:** [May 31, 2007, 10:32pm UTC](https://www.ruby-forum.com/t/help-with-using-rss-parser-in-a-rails-project/105629/2 "2007-05-31T22:32:15Z")

</div>

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!
