2
votes

Im trying to set up thinking sphinx in my rails 3 app. I set up mysql and installed sphinx without error. In my gemfile i have

gem "riddle", "~> 1.5.0"
gem "thinking-sphinx", "~> 2.0.10"

These install fine. In my model i have

define_index do
    indexes :name
    indexes acad_field
    indexes expertise
    indexes interests
    indexes experience
    indexes marital_status
    indexes email
    indexes place_of_birth
    indexes birthyear
    indexes hometown
    indexes current_residence
    indexes languages
    indexes nationalities
    indexes ethnicities_mom_dad
    indexes institution
    indexes program

end

and in my index in my controller i have

def index
 #@profiles = Profile.all
 @profiles = Profile.search params[:search]
 respond_to do |format|
   format.html # index.html.erb
   format.json { render :json => @profiles }
 end
end

in my routes i have

match "profiles?search=:search", :to => "profiles#index"

when i try running a search i get the error

Routing Error

undefined method `define_index' for #<Class:0xb3ada670>

What i am doing wrong here.

3

3 Answers

2
votes

I just needed to run

rake thinking_sphinx:rebuild

in terminal

0
votes

Based on @fuzzyalej comment, the needed steps are:

  • Replace correspondent gem line to gem "thinking-sphinx", "~> 2.0.10", :require => 'thinking_sphinx'
  • You do not need add ?search=:search to routing match, because rails can accept GET variables without other specifications.
0
votes

you probably didn't run 'bundle install' after adding the gem specification in your gemfile, I don't think rake ts:rebuild actually solved this issue :)