思考Sphinx 3.1 NameError:生产模式中未初始化的常量

时间:2014-09-27 23:00:43

标签: ruby-on-rails-3.2 thinking-sphinx nameerror uninitialized-constant

使用db MySQL在rails 3.2.17上进行项目。 使用Thinking Sphinx 3.1。 我在索引中只有两个模型:Group和Product。

在开发模式下,即使在生产服务器上,一切也能完美运行。 我在生产服务器上创建了开发数据库以进行测试。

但是当我尝试跑步时: export RAILS_ENV =生产 rake ts:重建 要么     rake ts:configure

我收到错误:

Generating configuration to /var/www/site/shared/config/sphinx.production.conf
rake aborted!
NameError: uninitialized constant Group
/var/www/site/shared/bundle/ruby/2.1.0/gems/activesupport-3.2.17/lib/active_support/inflector/methods.rb:230:in `block in constantize'
/var/www/site/shared/bundle/ruby/2.1.0/gems/activesupport-3.2.17/lib/active_support/inflector/methods.rb:229:in `each'
/var/www/site/shared/bundle/ruby/2.1.0/gems/activesupport-3.2.17/lib/active_support/inflector/methods.rb:229:in `constantize'
/var/www/site/shared/bundle/ruby/2.1.0/gems/activesupport-3.2.17/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/core/index.rb:43:in `model'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/index.rb:9:in `append_source'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/interpreter.rb:63:in `__source'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/interpreter.rb:20:in `indexes'
/var/www/site/releases/20140927155218/app/indices/group_index.rb:10:in `block in <top (required)>'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/core/interpreter.rb:3:in `translate!'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/core/index.rb:39:in `interpret_definition!'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/index.rb:32:in `sources'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration/consistent_ids.rb:31:in `collect'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration/consistent_ids.rb:31:in `sources'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration/consistent_ids.rb:19:in `attributes'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration/consistent_ids.rb:23:in `sphinx_internal_ids'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration/consistent_ids.rb:7:in `reconcile'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:87:in `render'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:96:in `block in render_to_file'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:96:in `render_to_file'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/rake_interface.rb:13:in `configure'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/tasks.rb:4:in `block (2 levels) in <top (required)>'
Tasks: TOP => ts:configure
(See full trace by running task with --trace)

我无法理解为什么。

请帮帮我!

我的索引定义

app / indices / group_index.rb

ThinkingSphinx::Index.define :group, :with => :active_record do
  # fields
#  indexes subject, :sortable => true
#  indexes content
#  indexes author.name, :as => :author, :sortable => true

  # attributes
#  has author_id, created_at, updated_at

    indexes :title_ua
    indexes :title_ru
    indexes :description_ua
    indexes :description_ru
    indexes :content_ua
    indexes :content_ru


end

应用程序/索引/ product_index.rb

ThinkingSphinx::Index.define :product, :with => :active_record do
  # fields
#  indexes subject, :sortable => true
#  indexes content
#  indexes author.name, :as => :author, :sortable => true

  # attributes
#  has author_id, created_at, updated_at

    indexes :title_ua
    indexes :title_ru
    indexes :description_ua
    indexes :description_ru
    indexes :brief_ua
    indexes :brief_ru
    indexes :permalink
    indexes :asin
    indexes :article
    indexes :mpn
    indexes :model


end

组模型迁移文件:

class CreateGroups < ActiveRecord::Migration
  def change
    create_table :groups do |t|
      t.string     :permalink
      t.integer    :position
      t.string     :title_ua
      t.string     :title_ru
      t.text       :description_ua, default: ''
      t.text       :description_ru, default: ''
      t.text       :content_ua,     default: ''
      t.text       :content_ru,     default: ''
      t.integer    :code_1c
      t.integer    :main_page_position
      t.string     :ancestry
      t.string     :category
      t.references :author
      t.references :update_by_user

      t.timestamps
    end
    add_index :groups, :permalink
    add_index :groups, :ancestry
  end
end

1 个答案:

答案 0 :(得分:1)

如评论中所述,使用threadsafe导致问题。我之前遇到过这个问题(我不认为它与Thinking Sphinx有关,只是关于在3.2.x中启用线程安全时Rails的自动加载和Rake如何协同工作。

我已经使用了以下方法 - 我非常确定应该没问题,前提是任何rake任务都没有做任何多线程的事情:

config.threadsafe! unless defined?($rails_rake_task) && $rails_rake_task

详细讨论here