Using Sunspot-Solr on a Rails Mountable Engine Model

It took me a lot of time to find/recognize this answer. I kept getting a no method error for Searchable when I had the Searchable block in my Engine’s model code. I put it there because that seems to be how Sunspot tells you to do it. But it won’t work on an Engine’s model (or on any other Gem’s model for all I know) since the model is not within the app.

The solution was to put the Searchable block in an initializer in my main app’s config directory.

For example:

# config/initializers/sunspot.rb

EngineName::ModelName.class_eval do
  searchable do
    text:name
    blah blah blah
  end
end

 

Comments on this entry are closed.