[英]Rails/Ruby/Postgres - LoadError cannot load such file -- pg_ext
I am trying to call a Ruby script (which connects to a postgres db) using the rails controller below, however it appears it is having problems loading one of the PG gem files.我正在尝试使用下面的 rails 控制器调用一个 Ruby 脚本(它连接到一个 postgres 数据库),但是它似乎在加载一个 PG gem 文件时遇到问题。 I have set my require statement to require 'pg' and tried the absolute path as well (require
/usr/local/rvm/gems/ruby-1.9.3-p194@railsTest/gems/pg-0.14.0/lib/pg/
).我已经将我的 require 语句设置为需要'pg'并尝试了绝对路径(需要
/usr/local/rvm/gems/ruby-1.9.3-p194@railsTest/gems/pg-0.14.0/lib/pg/
)。 The file 'pg_ext' is in fact present in the directory.文件“pg_ext”实际上存在于目录中。 Additionally, I can run the ruby script standalone without any problems (dbrubyscript.rb), however when rails is added to this equation it craps out with a
cannot load such file -- pg_ext
error.此外,我可以独立运行 ruby 脚本而不会出现任何问题 (dbrubyscript.rb),但是当将 rails 添加到此等式时,它会出现
cannot load such file -- pg_ext
错误。
Any direction here would be much appreciated as I have not been able to find anything online that fixes this issue这里的任何方向将不胜感激,因为我无法在网上找到任何解决此问题的方法
Rails controller:导轨控制器:
class TestdlController < ApplicationController
def runmyscript
load "/usr/local/rvm/my_app/ruby_scripts/reports/dbrubyscript.rb"
send_file '/usr/local/rvm/tmp/failedtests.csv', :type => 'text/csv', :disposition => 'inline'
flash[:notice] = "Reports are being processed..."
end
end
.rb file (dbrubyscript.rb) has the following: .rb 文件 (dbrubyscript.rb) 具有以下内容:
require 'rubygems'
require 'pg'
connects to (production) database
@conn = PGconn.connect("zzzzz.test.prod", 5432,"","","yyyyy_prod" ,"postgres", "xxxxxx")
.....
Trace Error: LoadError in TestdlController#runmyscript跟踪错误: TestdlController#runmyscript 中的 LoadError
cannot load such file -- pg_ext
无法加载这样的文件 -- pg_ext
Rails.root: /usr/local/rvm/my_app Application Trace |
Rails.root: /usr/local/rvm/my_app 应用程序跟踪 | Framework Trace |
框架跟踪 | Full Trace app/controllers/Testdl_controller.rb:3:in `runmyscript'
完整跟踪 app/controllers/Testdl_controller.rb:3:in `runmyscript'
This error occurred while loading the following files:
加载以下文件时发生此错误:
/usr/local/rvm/my_app/ruby_scripts/reports/dbrubyscript.rb/usr/local/rvm/my_app/ruby_scripts/reports/dbrubyscript.rb
/usr/local/rvm/gems/ruby-1.9.3-p194@railsTest/gems/pg-0.14.0/lib/pg//usr/local/rvm/gems/ruby-1.9.3-p194@railsTest/gems/pg-0.14.0/lib/pg/
pg_extpg_ext
Try running ruby /usr/local/rvm/gems/ruby-1.9.3-p194@railsTest/gems/pg-0.14.0/lib/pg/ext/extconf.rb and see what errors you get.尝试运行 ruby /usr/local/rvm/gems/ruby-1.9.3-p194@railsTest/gems/pg-0.14.0/lib/pg/ext/extconf.rb 看看你得到了什么错误。 That helped me determine that in my case, my PostgreSQL client was too old.
这帮助我确定,就我而言,我的 PostgreSQL 客户端太旧了。 Your error may be different since you appear to have a current-ish versioninstalled.
您的错误可能有所不同,因为您似乎安装了当前版本。
I had the same problem.我有同样的问题。 I have a stand alone ruby script.
我有一个独立的红宝石脚本。 It connects via
pg
to postgres
and worked if I ran it directly from the shell
.它通过
pg
连接到postgres
,如果我直接从shell
运行它就可以工作。
If I tried to run it via rspec I get the Error cannot load such file -- pg
.如果我尝试通过 rspec 运行它,我会收到错误
cannot load such file -- pg
。
Solved : The problem for rspec was, the pg
gem was not defined in the Gemfile
.已解决:rspec 的问题是,
pg
gem 未在Gemfile
中定义。 After put pg into Gemfile
, and retestet via rspec, it worked.将 pg 放入
Gemfile
并通过 rspec 重新测试后,它起作用了。
Try adding a line to your Gemfile:尝试在 Gemfile 中添加一行:
gem "pg"
Then run bundler via the command line:然后通过命令行运行 bundler:
bundle install
Rails uses Bundler to manage your gems and dependencies. Rails 使用 Bundler 来管理您的 gem 和依赖项。 You can read a bit more about the idea behind Bundler here: http://gembundler.com/v1.2/rationale.html
您可以在此处详细了解 Bundler 背后的理念:http: //gembundler.com/v1.2/rationale.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.