1

在rails 3.2.17上使用db MySQL创建项目。 使用思维狮身人面像3.1。 而我在索引中只有两个模型:组和产品。Thinking Sphinx 3.1 NameError:在生产模式下未初始化的常量

在开发模式下,即使在生产服务器上,一切正常。 我在生产服务器上创建了用于测试的开发数据库。

但是当我尝试运行: 出口RAILS_ENV =生产 耙TS:重建 或 耙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) 

我不明白为什么。

请帮帮我!

我的索引定义

应用/索引/ 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 
+0

你可以分享你的索引定义 – pat 2014-09-27 23:05:01

+0

是的,。?当然 – greenif 2014-09-27 23:17:04

+0

错误指向你的group_index.rb文件的第10行 - 但是,没有10行 那里。实际文件有什么不同? – pat 2014-09-28 03:01:14

回答

1

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

我已经使用了以下方法 - 这我肯定要罚款没有提供rake任务是做任何事情,就是多线程:

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

更详细地讨论here

相关问题