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 = ''<p>lorem ipsum <a href="http://dolor.com/">dolor</a> sit amet.</p>''=> "<p>lorem ipsum <a href=\"http://dolor.com/\">dolor</a> sit amet.</ p>">> doc = Hpricot(str)=> #<Hpricot::Doc {elem <p> "lorem ipsum " {elem <a href="http:// dolor.com/"> "dolor" </a>} " sit amet." </p>}>>> 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 = ''<p>lorem ipsum <a href="http://dolor.com/">dolor</a> sit amet.</p>''=> "<p>lorem ipsum <a href=\"http://dolor.com/\">dolor</a> sit amet.</ p>">> doc = Hpricot(str)=> #<Hpricot::Doc {elem <p> "lorem ipsum " {elem <a href="http:// dolor.com/"> "dolor" </a>} " sit amet." </p>}>>> doc/''p''=> #<Hpricot::Elements[{elem <p> "lorem ipsum " {elem <a href="http:// dolor.com/"> "dolor" </a>} " sit amet." </p>}]>>>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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 9 Apr 2008, at 03:37, Nilesh wrote:> > 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 = ''<p>lorem ipsum <a href="http://dolor.com/">dolor</a> sit >>> amet.</p>'' > => "<p>lorem ipsum <a href=\"http://dolor.com/\">dolor</a> sit amet.</ > p>" >>> doc = Hpricot(str) > => #<Hpricot::Doc {elem <p> "lorem ipsum " {elem <a href="http:// > dolor.com/"> "dolor" </a>} " sit amet." </p>}> >>> 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 >>>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> > However, IRB gives me a correct result: > > $ irb >>> require ''hpricot'' > => true >>> str = ''<p>lorem ipsum <a href="http://dolor.com/">dolor</a> sit >>> amet.</p>'' > => "<p>lorem ipsum <a href=\"http://dolor.com/\">dolor</a> sit amet.</ > p>" >>> doc = Hpricot(str) > => #<Hpricot::Doc {elem <p> "lorem ipsum " {elem <a href="http:// > dolor.com/"> "dolor" </a>} " sit amet." </p>}> >>> doc/''p'' > => #<Hpricot::Elements[{elem <p> "lorem ipsum " {elem <a href="http:// > dolor.com/"> "dolor" </a>} " sit amet." </p>}]> >>> > > 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. > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 9, 11:51 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 9 Apr 2008, at 12:27, Nilesh wrote:> > On Apr 9, 11:51 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > 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?In exactly the same way. I would put a breakpoint where the error happens and try and work out what''s going on. Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 9, 4:35 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---