【发布时间】:2015-07-15 03:31:08
【问题描述】:
我目前正在托管一个简单的 Ruby 脚本,用于存储 URL 和分数并将它们保存到 YAML。但是,我想保存到 Postgresql 数据库,因为每次重新启动应用程序时都会删除 yaml 文件。这是我在 Heroku 中遇到的错误:
could not connect to server: No such file or directory (PG::ConnectionBad)
这是一个在本地工作的示例脚本,但在 Heroku 中引发了上述错误:
require 'pg'
conn = PG.connect( dbname: 'template1' )
res1 = conn.exec('SELECT * from pg_database where datname = $1', ['words'])
if res1.ntuples == 1 # db exists
# do nothing
else
conn.exec('CREATE DATABASE words')
words_conn = PGconn.connect( :dbname => 'words')
words_conn.exec("create table top (url varchar, score integer);")
words_conn.exec("INSERT INTO top (url, score) VALUES ('http://apple.com', 1);")
end
提前感谢您的任何帮助或建议!
【问题讨论】:
标签: ruby postgresql heroku