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
user1562080
source share