2013-05-12 107 views
0

當我運行rake ts:index或rake ts:configure時得到這個錯誤。我不記得我嘗試過的所有事情 - 我發現的大部分解決方案都與舊版本的gem等有關。顯然,它不是我的define_index定義,我按照最新的思想 - 獅身人面像自述。未定義的方法`define_index'與思維 - 斯芬克斯

Generating configuration to /Users/Eamon/projectsgmb/gmb/config/development.sphinx.conf 
rake aborted! 
undefined method `define_index' for #<Class:0x007ffba4e51120> 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.13/lib/active_record/dynamic_matchers.rb:55:in `method_missing' 
/Users/Eamon/projectsgmb/gmb/app/models/item.rb:4:in `<class:Item>' 
/Users/Eamon/projectsgmb/gmb/app/models/item.rb:1:in `<top (required)>' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:469:in `load' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:469:in `block in load_file' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:639:in `new_constants_in' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:468:in `load_file' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:353:in `require_or_load' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:502:in `load_missing_constant' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:192:in `block in const_missing' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:190:in `each' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:190:in `const_missing' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/inflector/methods.rb:230:in `block in constantize' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/inflector/methods.rb:229:in `each' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/inflector/methods.rb:229:in `constantize' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/core_ext/string/inflections.rb:54:in `constantize' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/core/index.rb:40:in `model' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/active_record/index.rb:9:in `append_source' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/active_record/interpreter.rb:56:in `__source' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/active_record/interpreter.rb:20:in `indexes' 
/Users/Eamon/projectsgmb/gmb/app/indices/item_index.rb:2:in `block in <top (required)>' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/core/interpreter.rb:3:in `translate!' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/core/index.rb:36:in `interpret_definition!' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/active_record/index.rb:28:in `sources' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/configuration/consistent_ids.rb:31:in `collect' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/configuration/consistent_ids.rb:31:in `sources' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/configuration/consistent_ids.rb:19:in `attributes' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/configuration/consistent_ids.rb:23:in `sphinx_internal_ids' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/configuration/consistent_ids.rb:7:in `reconcile' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/configuration.rb:76:in `render' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/configuration.rb:84:in `block in render_to_file' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/configuration.rb:84:in `open' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/configuration.rb:84:in `render_to_file' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/rake_interface.rb:4:in `configure' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/rake_interface.rb:31:in `index' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/tasks.rb:9:in `block (2 levels) in <top (required)>' 
/Users/Eamon/.rvm/gems/[email protected]/gems/rake-10.0.4/lib/rake/task.rb:246:in `call' 
/Users/Eamon/.rvm/gems/[email protected]/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute' 
/Users/Eamon/.rvm/gems/[email protected]/gems/rake-10.0.4/lib/rake/task.rb:241:in `each' 
/Users/Eamon/.rvm/gems/[email protected]/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute' 
/Users/Eamon/.rvm/gems/[email protected]/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain' 
/Users/Eamon/.rvm/gems/[email protected]/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain' 
/Users/Eamon/.rvm/gems/[email protected]/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke' 
/Users/Eamon/.rvm/gems/[email protected]/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task' 
/Users/Eamon/.rvm/gems/[email protected]/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level' 
/Users/Eamon/.rvm/gems/[email protected]/gems/rake-10.0.4/lib/rake/application.rb:101:in `each' 
/Users/Eamon/.rvm/gems/[email protected]/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level' 
/Users/Eamon/.rvm/gems/[email protected]/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads' 
/Users/Eamon/.rvm/gems/[email protected]/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level' 
/Users/Eamon/.rvm/gems/[email protected]/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run' 
/Users/Eamon/.rvm/gems/[email protected]/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling' 
/Users/Eamon/.rvm/gems/[email protected]/gems/rake-10.0.4/lib/rake/application.rb:70:in `run' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `eval' 
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `<main>' 
Tasks: TOP => ts:index 

指數/ item_index.rb

ThinkingSphinx::Index.define :item, :with => :active_record do 
    indexes name 
    indexes ftype 
    indexes description 
end 

items_controller.rb

class ItemsController < ApplicationController 
    require 'thinking_sphinx' 

    ...  

    def index 
    @items = Item.search params[:search] 

    respond_to do |format| 
     format.html # index.html.erb 
     format.json { render json: @items } 
    end 
    end 

    ... 

end 

item.rb的

class Item < ActiveRecord::Base 
    attr_accessible :description, :ftype, :name 

    define_index do 
    indexes name 
    indexes ftype 
    indexes description 

    has created_at, updated_at 
    end 

    validates :name, presence: true, length: { maximum: 50 } 
    validates :ftype, presence: true, length: { maximum: 50 } 
    validates :description, presence: true, length: { maximum: 100 } 
end 

回答

2

define_index方法是在使用中的3.0.0版本之前思維獅身人面像。現在索引定義使用ThinkingSphinx::Index.define方法並駐留在app/indices/文件夾中,而不是模型文件。實際上,您已經有了新的定義,因此您可以從item.rb中刪除define_index代碼塊。

+0

太棒了!非常感謝!這是記錄在哪裏?... nm - 我沒有注意到明亮的讀取「v1/v2」標題...我的錯誤。 – ewizard 2013-05-13 01:29:55