Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 未定义的方法`定义索引';用斯芬克斯思考_Ruby On Rails_Ruby_Indexing_Thinking Sphinx_Configure - Fatal编程技术网

Ruby on rails 未定义的方法`定义索引';用斯芬克斯思考

Ruby on rails 未定义的方法`定义索引';用斯芬克斯思考,ruby-on-rails,ruby,indexing,thinking-sphinx,configure,Ruby On Rails,Ruby,Indexing,Thinking Sphinx,Configure,运行rake ts:index或rake ts:configure时出现此错误。我记不起我尝试过的每件事了——我发现的大多数解决方案都与gems的旧版本有关,等等。显然,我不是按照最新思维的sphinx自述文件的指示将define_索引定义放在Indexs文件夹中的 Generating configuration to /Users/Eamon/projectsgmb/gmb/config/development.sphinx.conf rake aborted! undefined meth

运行rake ts:index或rake ts:configure时出现此错误。我记不起我尝试过的每件事了——我发现的大多数解决方案都与gems的旧版本有关,等等。显然,我不是按照最新思维的sphinx自述文件的指示将define_索引定义放在Indexs文件夹中的

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/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/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
项目\u 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
class ItemsController
项目1.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
class项
定义索引
方法在Thinking Sphinx 3.0.0版之前就已使用。现在索引定义使用
ThinkingSphinx::index。定义
方法并驻留在
app/index/
文件夹中,而不是模型文件中。实际上,您已经有了新的样式定义,因此您可以从
item.rb

中删除
define\u index
代码块!非常感谢!这有什么记录吗?…纳米-我没有注意到明亮的“v1/v2”标题…我的错误。
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