Rss feeds

Using Rss Parser I loaded Some Url’s into the database.
All The Rss feeds has been stored in the table.
All The Rss Stories Has Been Stored In the Stories Table.
Stories Table Has Fields Like Story Name Story Description
Story Description Fields Contains Images Too…
That Story description must Not Contain Images
I want to restrict the images Not to be shown in the view.
Images has to be displayed separetely.Not Inside the Story Description
field.
I Extracted the Images and dispalyed separately using Hpricot.
But My Story Description Field Shows the Images. I don’t Know How to
Restrict the Images To Be Shown…
Any Advices…

My COde Starts Here

require ‘rss’
require ‘open-uri’
require ‘hpricot’

@feeds = Feed.find(:all)
@feeds.each do |f|
puts f.url
feed = RSS::Parser.parse(f.url)

puts “== #{feed.channel.title} ==”
puts “channel name: #{feed.channel.title}”
feed.items.each do |item|
puts “Title: #{item.title}”
puts “URL: #{item.link}”

puts “Description: #{item.description}”

@stories = Story.new
@stories.title = item.title
@stories.description = item.description
@stories.feed_id = item.id
@stories.guid = item.guid

doc = Hpricot.parse(item.description)
imgs = doc.search("//img")

@src_array = imgs.collect{|img|img.attributes[“src”]}

@src_array = @src_array.to_s

@stories.picture = @src_array
@stories.save

end
end

Newb N. wrote:

doc = Hpricot.parse(item.description)
imgs = doc.search("//img")

@src_array = imgs.collect{|img|img.attributes[“src”]}

Instead of the last line, does this work?

imgs.each do |img|
  img.attributes['src'] = nil
end

@stories.save

Now remember what I said about alternate kinds of images!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs