1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
def save_feed @feed = FeedTools::Feed.open('http://losangeles.craigslist.org/apa/index.rss') @feed.items.each_with_index do |item,i| feedd = Feeddetail.find(:first,:conditions => ["link =?",item.link]) if feedd.nil? then fdetail = Feeddetail.new fdetail.feed_id = 1 fdetail.title = item.title fdetail.link = item.link.strip fdetail.description = item.description fdetail.pubdate=item.published fdetail.save end end end
Refactorings
No refactoring yet !
Roderic Green
May 12, 2008, May 12, 2008 10:51, permalink
1 2 3 4 5 6 7 8 9 10 11
def save_feed @feed = FeedTools::Feed.open('http://losangeles.craigslist.org/apa/index.rss') @feed.items.each_with_index do |item,i| Feeddetail.find_or_create_by_link( :link => item.link.strip, :feed_id = i, :title => item.title, :description = item.description, :pubdate=item.published) end end
Its very simple method which uses FeedTools gem to collect feed items from url.Then I am storing them in a feeddetails table before that (line no 3) I just make sure that there won't be duplicate entry.
I am new to rails I think this method can be refactor.
Thanks in advance