Sunspot_Rails - undefined method `searchable' on page
Asked Answered
H

5

13

I have a model with a searchable block, like so:

class Contact < ActiveRecord::Base
  searchable do
    text :contact_name, :company_name, :contact_email
  end  
end

In the controller's index action, I'm calling Contact.new, which is giving me an error message on the page, which is currently running on our Staging server:

undefined method `searchable' for #<Class:0xce0bf80>

The stack trace is pointing to the searchable block in the Model via the Contact.new line in the controller.

When I run the code locally, either on the webpage or the console, or through the console on the Staging server, this error isn't appearing - only on the Staging webpage.

The Solr service is running fine on the Staging server, and the data has been indexed successfully. Any theories as to why it's not playing ball in Staging will be accepted.

EDIT

In response to Nick's question below, the Gemfile just has this line for Sunspot: gem 'sunspot_rails'

For Gemfile.lock, these are all the lines I could spot containing Sunspot or Solr references:

GEM
  rsolr (0.12.1)
    builder (>= 2.1.2)
  sunspot (1.2.1)  
    escape (= 0.0.4)  
    pr_geohash (~> 1.0)  
    rsolr (= 0.12.1)  
  sunspot_rails (1.2.1)  
    nokogiri  
    sunspot (= 1.2.1)

DEPENDENCIES
  sunspot_rails
Hyphen answered 11/8, 2011 at 16:44 Comment(2)
I am having the same problem. Did you ever manage to get this resolved?Sidelong
What version of Ruby, Rails, RubyGems and Bundler are you using? I ended upgrading RubyGems and Bundler and the problem (magically) went away.Sidelong
P
13

I had the same problem, and I just had to restart my rails server. Simple solution, but if it wasn't for another post somewhere that suggested I do so, I would probably have tried to debug the error for a much longer time before just trying to restart the server, hehe...

Presage answered 13/3, 2012 at 14:4 Comment(0)
L
5

This can also happen if you forget to restart your rails server after installing the new sunspot gem

Limitation answered 14/7, 2012 at 2:23 Comment(0)
L
0

Sounds to me like the gem isn't being loaded correctly on your staging site. If you can show the relevant sections of your Gemfile and Gemfile.lock, I can update with more of an answer.

EDIT — Gemfile looks fine. Sorry, but I've got nothin' without being able to get my hands on the app. Report a bug to the Sunspot mailing list? http://outoftime.github.com/sunspot

Latrice answered 11/8, 2011 at 19:17 Comment(0)
C
0

After reading this post I understood that the problem is because the rake tasks line prevents the loading of Sunspot I managed to solve it in the following way:

I removed the following line from my Rakefile require 'sunspot/rails/tasks'

I created a sunspot.rake file and added to it the contents of the following file from the sunspot gem source: /gems/sunspot_rails-1.2.1/lib/sunspot/rails/tasks.rb

I know that this a hack, but it is working.

Caliche answered 7/3, 2012 at 15:10 Comment(0)
C
0

I just ran spring stop and it fixed it

Chalcography answered 30/6, 2018 at 19:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.