在Sinatra中使用pg sql-lite适配器时出错

时间:2012-11-13 19:27:44

标签: sqlite postgresql

我在连接Sinatra的开发数据库时遇到问题。正在做后端的那个人在纽约,现在还没有。我对前端比较熟悉,并且想知道,有什么简单的东西我不知道吗?

生产数据库连接,好吧,但是当我尝试在开发模式下启动时,我在终端中遇到了一堆错误。我也尝试使用端口5432启动瘦功能但没有成功。

任何想法? 编辑添加了下面的models.rb

终端

mdb|moreButton⚡ ⇒ ruby app.rb   
/Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/data_objects-0.10.10/lib/data_objects/connection.rb:79:in `initialize': could not connect to server: Connection     refused (DataObjects::ConnectionError)
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?
could not connect to server: Connection refused
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 5432?
could not connect to server: Connection refused
    Is the server running on host "localhost" (fe80::1) and accepting
    TCP/IP connections on port 5432?
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/data_objects-0.10.10/lib/data_objects/connection.rb:79:in `new'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/data_objects-0.10.10/lib/data_objects/pooling.rb:181:in `block in new'
    from <internal:prelude>:10:in `synchronize'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/data_objects-0.10.10/lib/data_objects/pooling.rb:176:in `new'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/data_objects-0.10.10/lib/data_objects/pooling.rb:121:in `new'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/data_objects-0.10.10/lib/data_objects/connection.rb:68:in `new'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:251:in `open_connection'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-transactions-1.2.0/lib/dm-transactions/adapters/dm-do-adapter.rb:69:in `open_connection'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:276:in `with_connection'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:33:in `select'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-migrations-1.2.0/lib/dm-migrations/adapters/dm-postgres-adapter.rb:45:in `schema_name'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-migrations-1.2.0/lib/dm-migrations/adapters/dm-do-adapter.rb:26:in `storage_exists?'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-migrations-1.2.0/lib/dm-migrations/auto_migration.rb:65:in `storage_exists?'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-migrations-1.2.0/lib/dm-migrations/auto_migration.rb:120:in `storage_exists?'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-constraints-1.2.0/lib/data_mapper/constraints/migrations/model.rb:22:in `auto_migrate_constraints_down'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-constraints-1.2.0/lib/data_mapper/constraints/migrations/singleton_methods.rb:39:in `block in     auto_migrate_constraints_down'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-core-1.2.0/lib/dm-core/support/descendant_set.rb:64:in `block in each'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-core-1.2.0/lib/dm-core/support/subject_set.rb:210:in `block in each'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-core-1.2.0/lib/dm-core/support/ordered_set.rb:319:in `block in each'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-core-1.2.0/lib/dm-core/support/ordered_set.rb:319:in `each'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-core-1.2.0/lib/dm-core/support/ordered_set.rb:319:in `each'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-core-1.2.0/lib/dm-core/support/subject_set.rb:210:in `each'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-core-1.2.0/lib/dm-core/support/descendant_set.rb:63:in `each'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-constraints-1.2.0/lib/data_mapper/constraints/migrations/singleton_methods.rb:38:in     `auto_migrate_constraints_down'
    from /Users/adam/.rvm/gems/ruby-1.9.3-p125@sinatra/gems/dm-constraints-1.2.0/lib/data_mapper/constraints/migrations/singleton_methods.rb:7:in `auto_migrate!'
    from /Users/adam/Git/mdb/models.rb:403:in `<top (required)>'
    from /Users/adam/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/adam/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from app.rb:1:in `<main>'

我的宝石

mdb|moreButton⚡ ⇒ gem list

*** LOCAL GEMS ***

addressable (2.2.8)
backports (2.6.4, 2.6.1)
bcrypt-ruby (3.0.1)
bundler (1.1.5)
daemons (1.1.9)
data_mapper (1.2.0)
data_objects (0.10.10, 0.10.8)
dm-adjust (1.2.0)
dm-aggregates (1.2.0)
dm-constraints (1.2.0)
dm-core (1.2.0)
dm-do-adapter (1.2.0)
dm-migrations (1.2.0)
dm-postgres-adapter (1.2.0)
dm-serializer (1.2.2, 1.2.1)
dm-sqlite-adapter (1.2.0)
dm-timestamps (1.2.0)
dm-transactions (1.2.0)
dm-types (1.2.2, 1.2.1)
dm-validations (1.2.0)
do_postgres (0.10.10, 0.10.8)
do_sqlite3 (0.10.10, 0.10.8)
eventmachine (1.0.0, 0.12.10)
fastercsv (1.5.5)
hpricot (0.8.6)
json (1.7.5, 1.6.7)
json_pure (1.7.5, 1.6.7)
mime-types (1.19)
multi_json (1.3.6, 1.0.4)
multimap (1.1.2)
rack (1.4.1)
rack-protection (1.2.0)
rack-test (0.6.2, 0.6.1)
rake (0.9.2.2)
rest-client (1.6.7)
rubygems-bundler (1.0.3)
rvm (1.11.3.5)
sass (3.2.1)
shotgun (0.9)
sinatra (1.3.3, 1.3.2)
sinatra-contrib (1.3.1)
sinatra-reloader (1.0)
stringex (1.4.0, 1.3.3)
thin (1.5.0)
tilt (1.3.3)
time-ago-in-words (0.1.2)
uuidtools (2.1.3, 2.1.2)

app.rb gemfile

source 'http://rubygems.org'
gem 'sinatra'
gem 'data_mapper'
gem 'hpricot'
gem 'dm-core'
gem 'json'
gem 'dm-postgres-adapter'
gem 'dm-adjust'
gem 'time-ago-in-words'
gem 'sass'
gem 'rest-client'
gem 'multimap'

group :development do
  gem "dm-sqlite-adapter"
  gem 'sinatra-reloader'
end

models.rb

if $development
    DataMapper.setup(:default, "postgres://localhost/mistakesdb_default")
else
    DataMapper.setup(:default, "postgres://giberish:giberish@ec2-23-21-209-147.compute-1.amazonaws.com:5432/giberish")
end
DataMapper.finalize
if $development
    #DataMapper.auto_upgrade!
    DataMapper.auto_migrate!
else
    DataMapper.auto_upgrade!
    #DataMapper.auto_migrate!
end

###### required.rb ######
$development = File.exists?('/Users/adam')

##### Top of app.rb #####
require "./models.rb"
require "./required.rb"
require "sinatra"
require "sass"
require "sinatra/reloader" if $development
require "time-ago-in-words"
require "rest_client"
require "multimap"

1 个答案:

答案 0 :(得分:1)

在开发模式下,DataMapper正在尝试连接到名为mistakesdb_default的本地PostgreSQL数据库。您似乎根本没有运行本地postgres安装,因此&#34;连接被拒绝&#34;错误。根据您的操作系统,您可以在http://www.enterprisedb.com/找到一个简单的postgres安装程序。