views:

17

answers:

2

Hi,

I am working on Ubuntu 10.04 and I am using feed-zirra to parse RSS feeds and I have MySQL database.

I am trying to parse RSS feeds from Times of India Top Stories. There seems to be problem with the first link, I am sure TOI guys will correct it soon. But anyway, I dont want to face similar error later so thats why I want to ask you guys how to solve this problem.

Just look at this and especially look for link

<item>
  <title>CWG: Abhinav Bindra, Gagan Narang win first Gold for India</title
  <description>Abhinav Bindra and Gagan Narang on Tuesday bagged Gold for the men's 10 m air rifle pair's event, getting India its first gold in the 19th Commonwealth Games.</description>
<link>/cwgarticleshow/6688747.cms</link>
<guid>/cwgarticleshow/6688747.cms</guid>
<pubDate>Tue, 05 Oct 2010 04:57:46 GMT</pubDate>
</item>

The link is <link>/cwgarticleshow/6688747.cms</link>

Now, when I click the link, in the view.. its getting routed to http://localhost:3000/cwgarticleshow/6688747.cms instead of http://timesofindia.indiatimes.com/cwgarticleshow/6688747.cms

And the error I am getting is

**Routing Error**

No route matches "/cwgarticleshow/6688747.cms" with {:method=>:get}

How do I correct this type of Error?

Looking forward for your help and support

Thanks

A: 

You just need to prepend http://timesofindia.indiatimes.com to the link tag value and you'll be ok.

Eimantas
I am a newbie. Could you tell me how can this be achieved? I didnt understand?
reko
A: 

You can use URI class. You can, for example, define following method

require "uri"

def repair_link(feed_link)
  uri = URI.parse(feed_link)
  uri.scheme ||= "http"
  uri.host   ||= "timesofindia.indiatimes.com"
  uri.to_s
end

It will set the scheme and host part of the URL if they are not already filled. So if you call it for normal link (like http://foo/bar.cms) then nothing will be changed.

And last thing - you probably should catch exception somewhere as the #parse method raises exception InvalidURIError in case of invalid URI. But it's up to you how you will deal with it.

pawien