Alex Rivera | Logout

undefined method "results" with Sunspot Solr Search

Asked 2011-10-28T06:09:04.253
10

I am using Rails 3.1 and have been using this railscast tutorial to implement sunspot. I am following everything right (i think) however when I run the search like this:

class ProductsController < ApplicationController
  # GET /products
  # GET /products.xml

  def index
    @search = Product.search do
      fulltext params[:search]
    end
    @products = @search.results
    respond_to do |format|
      format.html
      format.xml  { render :xml => @products }
    end
  end...

Here's how I have declared the searchable in my product.rb file

searchable do
    text :title
end

However I keep running in to the following error

undefined method `results' for #<MetaSearch::Searches::Product:0x12a089f50>

But when I do just a @products = @search, i get a full list of all the products, no matter what i send in the search query

Anyone have any idea what I am doing wrong?

Edit
Report

1 Answer

18

Sunspot will refuse to define the class search method if the class already has one defined. You can instead use the solr_search method to the same effect.

answered 2011-10-31T22:57:46.200

Your Answer