Hpricot for help!

Hi,there

I’ve recently used hpricot to parse xml result. The code is as shown in
http://apassant.net/blog/post/2006/08/29/108-geolocation-with-ruby-on-rails-and-google-maps

while I seem to be able to get it to work in irb, it didn’t work in my
application.

The difference seems to be in
require ‘open-uri’
require ‘rubygems’
require ‘hpricot’

while in irb, they all return true. in the function that’s being
called,I setup a breakpoint and can see that these three values are
false.

anybody has ideas what happened?

Greatly appreciated for any help!

Is your rails app definitely hitting the same ruby binary that
running irb or your command-line ruby script? Almost sounds like
either you’re hitting a second (or older) install that doesn’t have
some of the libs you’re trying to require, or else ruby’s load paths
are getting jacked up somewhere along the way if the requires are in
fact failing in your rails app.

Also, you may want to check out the google_geocode library:

http://dev.robotcoop.com/Libraries/google-geocode/

I’ve used it in essentially the same exact way you’ve described in
your blog post, as a before_save in my model, works wonderfully.
Looks like your method would work just as well, just thought I’d
point out an alternate solution.

Thanks for your reply JD. You might be right since I’ve installed
a few ruby versions and need to clean up.

I setup the ruby path to C:/ruby/bin; so I thought both of the
applications
and irb should go for this path? how do I check if they use the same
ruby binary?

Thanks!

JD Harrington wrote:

Is your rails app definitely hitting the same ruby binary that
running irb or your command-line ruby script? Almost sounds like
either you’re hitting a second (or older) install that doesn’t have
some of the libs you’re trying to require, or else ruby’s load paths
are getting jacked up somewhere along the way if the requires are in
fact failing in your rails app.

Also, you may want to check out the google_geocode library:

http://dev.robotcoop.com/Libraries/google-geocode/

I’ve used it in essentially the same exact way you’ve described in
your blog post, as a before_save in my model, works wonderfully.
Looks like your method would work just as well, just thought I’d
point out an alternate solution.

On 11/21/06, jacquie [email protected] wrote:

require ‘open-uri’
require ‘rubygems’
require ‘hpricot’

while in irb, they all return true. in the function that’s being
called,I setup a breakpoint and can see that these three values are
false.

anybody has ideas what happened?

Greatly appreciated for any help!

If require returns false it only means the library is already loaded -
it doesn’t mean there is an error. If there is an error require
raises an exception.

So in your app you already have those libraries loaded when you
require - so its nothing to worry about .