简体   繁体   English

Rails:不能包含pg_search Gem提供的PgSearch模块

[英]Rails : Cannot include PgSearch Module provided by the pg_search Gem

TO SUM UP : 总结一下 :

The module PgSearch provided by the Gem pg_search cannot be included, required or loaded on the staging environment (Rbenv, nginx, unicorn,capistrano), the problem happens on the web server through http but does not appear on the staging server's rails command. 不能在临时环境(Rbenv,nginx,unicorn,capistrano)上包括,必需或加载Gem pg_search提供的模块PgSearch,该问题通过http在Web服务器上发生,但未出现在临时服务器的rails命令上。 An other module provided by an other gem can be included without error. 可以包含其他gem提供的其他模块,而不会出现错误。

No problem on the local development environment (rvm, puma). 在本地开发环境(rvm,puma)上没有问题。

DETAILS 细节

I am currently developing a Ruby On Rails 4.0 application with ruby 2.0.0 which git repositories are hosted on bitbucket. 我目前正在使用ruby 2.0.0开发Ruby On Rails 4.0应用程序,其git存储库托管在bitbucket上。 I deploy the app through a staging server using capistrano. 我使用capistrano通过登台服务器部署应用程序。

  • Staging server environment : rbenv, nginx and unicorn 登台服务器环境:rbenv,nginx和独角兽
  • Local development environment : rvm and puma 本地开发环境:rvm和puma

The rails environnment files (environment/production.rb & environment/staging.rb) for both are the same. 两者的rails环境文件(environment / production.rb和environment / staging.rb)是相同的。

WHAT DID I DO : 我做了什么:

I have installed the pg_search gem (a PostgreSQL full text search gem) by adding it to my Gemfile and put the clause "include PgSearch" in the Active Record model I wanted to use with pg_search gem 我已经通过将pg_search gem(PostgreSQL全文搜索gem)添加到我的Gemfile中,并在要与pg_search gem一起使用的Active Record模型中放置了“ include PgSearch”子句,来安装它。

I have run the app in development mode... it works ! 我已经在开发模式下运行该应用程序了...它有效!

PROBLEM : 问题:

After having deployed the changes to the staging server : Through the http server I get this error : 将更改部署到登台服务器后:通过http服务器,我收到此错误:

NameError in App::MyController#index Uninitialized constant MyActiveRecordModel::PgSearch App :: MyController#index中的NameError未初始化的常量MyActiveRecordModel :: PgSearch

(Normally, this pg_search gem which is included in the GemFile should have its lib/*.rb files included in the autoload search path and a clause like load "pg_search.rb", require"pg_search" or "include PgSearch" (module included in pg_search.rb file) should pass. (通常,包含在GemFile中的此pg_search gem应该在自动加载搜索路径中包含其lib / *。rb文件,并在诸如load“ pg_search.rb”之类的子句中要求“ pg_search”或“ include PgSearch” (包含模块pg_search.rb文件中)。

In order to find clues to fix the bug, I have : 为了找到修复该错误的线索,我有:

-tried if an other module provides by the gem could be included ... It works -尝试是否可以包含gem提供的其他模块...有效

After been to the current release path of the staging server I run "bundle exec rails c staging" and tried to : 进入登台服务器的当前发行版路径后,我运行“ bundle exec rails c登台”并尝试:

  • see if the ActiveRecord Model ( which I included PgSearch) instanciation works. 看看ActiveRecord模型(我包括PgSearch)实例化是否可行。

  • see if the Module provided by the gem could be found / loaded on the server and I have executed - include PgSearch and require "pg_search" and load "pg_search.rb". 看看是否可以在服务器上找到/加载gem所提供的模块,并且已经执行-包含PgSearch并要求“ pg_search”并加载“ pg_search.rb”。

All these commands were a succeess. 所有这些命令都是成功的。

I run out of ideas to find some other clues, would you have any suggestions please ? 我用尽了所有其他线索的想法,请问您有什么建议吗?

Thank you. 谢谢。

Restart the rails server 重新启动Rails服务器

Gems introduce new code that rails will need to access. 宝石介绍了Rails需要访问的新代码。 To make the new code available to Rails we go through 3 steps: 为了使新代码可用于Rails,我们经历了3个步骤:

  1. Change the Gemfile 更改宝石文件
  2. bundle install 捆绑安装
  3. Restart the rails server 重新启动Rails服务器

It is easy to forget a step. 很容易忘记一个步骤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM