Rails / Ruby / Postgres - LoadError cannot load such a file - pg_ext

I am trying to call a Ruby script (which connects to postgres db) using the rails controller below, however, it seems to be having problems loading one of the PG gem files. I installed the require statement for the query "pg" and also tried the absolute path (require /usr/local/rvm/gems/ ruby-1.9.3-p194@railsTest /gems/pg-0.14.0/lib/pg/ ). The pg_ext file is indeed present in the directory. In addition, I can run the ruby ​​script autonomously without any problems (dbrubyscript.rb), however, when the rails are added to this equation, it deceives the error cannot load such file -- pg_ext .

Any direction here would be greatly appreciated as I could not find anything on the Internet that fixes this problem.

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 

The .rb file (dbrubyscript.rb) has the following:

 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

cannot load such a file - pg_ext

Rails.root: / usr / local / rvm / my_app Application Trace | Frame trace | Application / Controllers Full Trace / 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 / gems / ruby-1.9.3-p194@railsTest /gems/pg-0.14.0/lib/pg/
pg_ext

+9
source share
3 answers

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. This helped me determine that in my case my PostgreSQL client was too old. Your error may be different because you find that the current version is installed.

0
source

I had the same problem. I have a separate ruby ​​script. It connects via pg to postgres and works if I run it directly from the shell .

If I tried to run it through rspec, I will get Error cannot load such file -- pg .

It is resolved . The problem for rspec was, the pg stone was not defined in the Gemfile . Putting pg in the Gemfile and try again through rspec, it worked.

0
source

Try adding a line to your gemfile:

 gem "pg" 

Then run the traveler through the command line:

 bundle install 

Rails uses the Bundler to manage your gems and dependencies. You can read a little more about Bundler's idea here: http://gembundler.com/v1.2/rationale.html

-2
source

All Articles