PaulC
PaulC

Reputation: 491

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

Upvotes: 13

Views: 2913

Answers (5)

Dorian
Dorian

Reputation: 23929

I just ran spring stop and it fixed it

Upvotes: 0

Jason Axelson
Jason Axelson

Reputation: 4665

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

Upvotes: 5

cakism
cakism

Reputation: 255

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

Upvotes: 13

Rubinsh
Rubinsh

Reputation: 4983

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.

Upvotes: 0

Nick Zadrozny
Nick Zadrozny

Reputation: 7944

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

Upvotes: 0

Related Questions