Peculiar Hpricot error in Rails app

Hi,

I have been stumped by this error Hpricot is generating in my rails
app. The error looks like this:

$ script/console
Loading development environment (Rails 2.0.2)

str = ‘

lorem ipsum dolor sit amet.


=> “

lorem ipsum <a href=“http://dolor.com/”>dolor sit amet.</
p>”

doc = Hpricot(str)
=> #<Hpricot::Doc {elem

“lorem ipsum " {elem “dolor” } " sit amet.”

}>

doc/‘p’
NoMethodError: You have a nil object when you didn’t expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
from /Library/Ruby/Gems/1.8/gems/hpricot-0.6/lib/hpricot/traverse.rb:
279:in `/’
from (irb):7

However, IRB gives me a correct result:

$ irb

require ‘hpricot’
=> true

str = ‘

lorem ipsum dolor sit amet.


=> “

lorem ipsum <a href=“http://dolor.com/”>dolor sit amet.</
p>”

doc = Hpricot(str)
=> #<Hpricot::Doc {elem

“lorem ipsum " {elem “dolor” } " sit amet.”

}>

doc/‘p’
=> #<Hpricot::Elements[{elem

“lorem ipsum " {elem “dolor” } " sit amet.”

}]>

I am using the system installed hpricot v0.6 gem (not in vendor/gems).
Now I am pretty sure this is not really Hpricot’s fault. The same code
works in a fresh rails application. Probably something in my code is
causing this error. But I am not able to see where. None of my other
plugins are using Hpricot. I am calling Hpricot only from one method
in application_helper.rb. This error cropped up when my frozen Rails
version was 2.0.1. I froze rails again to the edge version (r9208).
But nothing helped.

Any pointers on where should I look to fix this? Any settings to tweak
in my rails app? I am lost on this right now.

Thanks!
Nilesh.

On 9 Apr 2008, at 03:37, Nilesh wrote:

=> "

lorem ipsum <a href=“http://dolor.com/”>dolor sit amet.</
from (irb):7

If you want to make things real interesting, the same thing from my
rails app was fine. Can’t think of anything better to suggest than to
step through it with the debugger and try and understand the problem a
little more.

Fred

On Apr 9, 11:51 am, Frederick C. [email protected]
wrote:

If you want to make things real interesting, the same thing from my
rails app was fine. Can’t think of anything better to suggest than to
step through it with the debugger and try and understand the problem a
little more.

Ok, how do I debug the Rails stack? I normally use debugger with the
‘ruby-debug’ gem. I can debug through my code but how do I debug the
stack and see how it loads Hpricot?

On 9 Apr 2008, at 12:27, Nilesh wrote:

‘ruby-debug’ gem. I can debug through my code but how do I debug the
stack and see how it loads Hpricot?

In exactly the same way. I would put a breakpoint where the error
happens and try and work out what’s going on.

Fred

It turned out to be a rogue plugin which was
carelessly overriding the String Class ‘match’ method to its own
hacked version. This caused the Hpricot error.

What was plugin that did this?

On Apr 9, 4:35 pm, Frederick C. [email protected]
wrote:

In exactly the same way. I would put a breakpoint where the error
happens and try and work out what’s going on.

I enabled the backtrace option, browsed through the application and
zeroed onto the problem. It turned out to be a rogue plugin which was
carelessly overriding the String Class ‘match’ method to its own
hacked version. This caused the Hpricot error. That teaches me for
indiscriminately using plugins!

Thanks Fred.

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