Ruby on rails 3.2 思考Sphinx 3.1 NameError:在生产模式下未初始化常量

Ruby on rails 3.2 思考Sphinx 3.1 NameError:在生产模式下未初始化常量,ruby-on-rails-3.2,thinking-sphinx,nameerror,uninitialized-constant,Ruby On Rails 3.2,Thinking Sphinx,Nameerror,Uninitialized Constant,在rails 3.2.17上有一个使用db MySQL的项目。 使用思考狮身人面像3.1。 我在索引中只有两个模型:组和产品 在开发模式下,即使在生产服务器上,一切都可以完美地工作。 我在生产服务器上创建了用于测试的开发数据库 但当我尝试跑步时: 导出RAILS_ENV=生产 rake ts:重建 或 rake ts:配置 我得到一个错误: Generating configuration to /var/www/site/shared/config/sphinx.production.conf

在rails 3.2.17上有一个使用db MySQL的项目。 使用思考狮身人面像3.1。 我在索引中只有两个模型:组和产品

在开发模式下,即使在生产服务器上,一切都可以完美地工作。 我在生产服务器上创建了用于测试的开发数据库

但当我尝试跑步时: 导出RAILS_ENV=生产 rake ts:重建 或 rake ts:配置

我得到一个错误:

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/index/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
class CreateGroups
如评论中所述,使用threadsafe会导致问题。我以前遇到过这种情况(我认为这与思考Sphinx无关,只是在3.2.x中启用threadsafe时Rails的自动加载和Rake如何协同工作

我使用了以下方法-如果没有rake任务执行任何多线程的任务,我很确定这应该是很好的:

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

详细讨论。

您能分享您的索引定义吗?错误指向group_index.rb文件的第10行-但是,那里没有10行。实际文件中有什么不同吗?我发布了我的组模型迁移文件。但我认为索引文件中没有问题,首先-非常简单,其次-它在deve中工作开发模式。您的生产环境是否启用了线程安全?是的,这就是问题所在!谢谢!!!
config.threadsafe! unless defined?($rails_rake_task) && $rails_rake_task