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. 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/
). The file 'pg_ext' is in fact present in the directory. 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.
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:
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 file -- pg_ext
Rails.root: /usr/local/rvm/my_app Application Trace | Framework Trace | Full Trace 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/gems/ruby-1.9.3-p194@railsTest/gems/pg-0.14.0/lib/pg/
pg_ext
gem 'pg'
to the Gemfile in Rails and install all gems with dependencies by runningbundle install
? – Near