Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sunspot_Rails - undefined method `searchable' on page

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
like image 704
PaulC Avatar asked Aug 11 '11 16:08

PaulC


2 Answers

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...

like image 186
cakism Avatar answered Oct 22 '22 01:10

cakism


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

like image 42
Jason Axelson Avatar answered Oct 22 '22 02:10

Jason Axelson