Forum: Ruby Hpricot question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7a0237a8c808db7572e49984372d5c6b?d=identicon&s=25 furfey@gmail.com (Guest)
on 2007-01-24 21:50
(Received via mailing list)
In a statement like this:

doc=Hpricot(open(url))

Is there a way to pull the url as a value from a database?
0b65e5c78322fc51abf326af6bd0d2d2?d=identicon&s=25 Jb Smith (jbsmith)
on 2007-01-25 18:01
furfey@gmail.com wrote:
> In a statement like this:
>
> doc=Hpricot(open(url))
>
> Is there a way to pull the url as a value from a database?

lets say you've done this in your controller where the Feed is a model
with a url field in it.

--feed_controller.rb

   def pullfeed
    @feed = Feed.find(params[:id])
    Parsefeed.parse(@feed.id)
   end

The @feed can be used to fetch the field with a url in it, in your
hpricot model.
if you have required 'open-uri' in your model. otherwise hpricot can
only open local resources.

--parsefeed.rb  is a model not subclassed from ActiveRecord if not
needed

class Parsefeed
 require 'hpricot'
 require 'open-uri'

  def self.parse(feedID)
    doc=[]
    @feed = Feed.find(feedID)
    doc = Hpricot(open(@feed.url))    #this is where you employ the url
from the database model
    <!---    add your doc parsing code below  -->
 end
end
This topic is locked and can not be replied to.