アーカイブを検索しましたが、私のジレンマに対する答えが見つかりませんでした。Ruby でコーディングしており、ローカルの Mac Yosemite で watir webdriver フレームワークを使用しており、Linux ボックスで postgres データベースに接続したいと考えています。
必要な ruby gem をローカル Mac にインストールしました
* 地元の宝石 *
- dbd-pg (0.3.9)
- ページ (0.18.4)
- dbi (0.4.5、0.4.4)
次のコードを使用しています。
require 'rubygems'
require 'pg'
require 'dbd/pg'
require 'dbi'
conn = PGconn.connect("10.0.xx.xx","5432",'','',"mydbname","dbuser", "")
res = conn.exec('select * from priorities_map;')
puts res.getvalue(0,0)
conn.close if conn
これを実行すると、これらのエラーが発生します
.initialize': Could not connect to server: Connection refused (PG::ConnectionBad)
Is the server running on host "10.0.xx.xx" and accepting
TCP/IP connections on port 5432?
コードを使用する場合
dbh = DBI.connect("dbi:pg:mydbname:ipaddress", "user", "")
row = dbh.exec('select * from etr_priorities_map;')
puts row.getvalue(0,0)
dbh.disconnect if dbh
エラーが発生します
block in load_driver': Unable to load driver 'pg' (underlying error: wrong constant name pg) (DBI::InterfaceError) from System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
私はRubyが初めてです。これらの問題を解決するにはどうすればよいですか?