EdgeRails: "undefined method `weight' for #<Hash:

Hi all,

I was playing with the sample project found on the Wiki at
Peak Obsession
, and everything was working fine, … till I moved to EdgeRails :
undefined method `weight’ for #Hash:0x22c7150

(full error thread below)

Any idea?

Alain

/Users/aravet/Desktop/Locomotive/Bundles/RubyonRails-1.0-Min.locobundle/Contents/Resources/unix/lib/ruby/site_ruby/1.8/ferret/search/index_searcher.rb:107:in
search' /Users/aravet/Desktop/Locomotive/Bundles/RubyonRails-1.0-Min.locobundle/Contents/Resources/unix/lib/ruby/site_ruby/1.8/ferret/index/index.rb:622:in do_search’
/Users/aravet/Desktop/Locomotive/Bundles/RubyonRails-1.0-Min.locobundle/Contents/Resources/unix/lib/ruby/site_ruby/1.8/ferret/index/index.rb:317:in
search_each' /Users/aravet/Desktop/Locomotive/Bundles/RubyonRails-1.0-Min.locobundle/Contents/Resources/unix/lib/ruby/1.8/monitor.rb:229:in synchronize’
/Users/aravet/Desktop/Locomotive/Bundles/RubyonRails-1.0-Min.locobundle/Contents/Resources/unix/lib/ruby/site_ruby/1.8/ferret/index/index.rb:316:in
search_each' #{RAILS_ROOT}/app/models/result.rb:27:in search_index’
#{RAILS_ROOT}/app/models/result.rb:15:in count' #{RAILS_ROOT}/app/controllers/search_controller.rb:31:in get_results’

Any idea

additional info: I also tried without the c extension, without success.

For the 1st unsuccessful attemp, I just installed the gem

$ gem install ferret.

For the 2nd attempt,
I uninstalled the gem
$ gem uninstall ferret.
and installed from the zip file, AND skipped the c extension
compilation, as indicated on Trac
$ ruby setup.rb config
$ ruby setup.rb install

I’ve looked in the ferret code and noticed that a weight method can be
found in the Query class, that doesn’t extend Hash. I’m puzzled by the
error message and more than annoyed, as my project runs on EdgeRails.

Alain

Hi, Alain,

since I’ve originally posted this HowTo to the RoR-wiki but haven’t got
the
time right now even for the small contribution of helping to keep this
site
up to date I’m not quite sure if it is about time to delete the sample
project. There has been happened so much in ferret as well as on rails
that
it’s no wonder that something isn’t working any longer. My advice right
now
is: Don’t be disappointed or annoyed but have a look at the ferret wiki
http://ferret.davebalmain.com and look at the integration efforts under
acts_as_ferret. There even is a svn-tree for integrating ferret with
rails.
You should find the location of this as well on the ferret wiki and in
the
archives of ferret-talk on http://www.ruby-forum.com. And maybe as you
are
going on you’ll have the time to update the rails wiki as well. Sorry
for
the unconvenience, but I’ve got exams in a few month and am learning all
the
time. All things IT aren’t really happening for me right now…

Best Regards
Jan P.

I started from scratch on EdgeRails, and it worked.
It’s strange though, that changing the Rails version has an impact on
Ferret (that doesn’t require Rails).

Alain

Hi Alain,

I’m glad the problem seems to have fixed itself. Basically what must
have been happening was that a Hash was being passed to the
search_each method instead of a String. The search_each method knows
how to convert a String to a Query but a Hash will cause the error you
saw. I don’t know exactly why changing the Rails version would do
something like that but I’ve had a similar problem in the past. That’s
why it’s EdgeRails. :smiley: Expect the next couple of versions of ferret to
be even less stable.

Cheers,
Dave

I posted a resolution to the “undefined method `weight’” error message
on the rails website:

http://wiki.rubyonrails.com/rails/pages/HowToIntegrateFerretWithRails

MikeR