2012-12-05 100 views
0

Frnds我已编辑database.yml如下我的postgresql数据库和下载PG宝石和相关libraries.I serached它在谷歌和编辑的方式..但后运行服务器它显示在终端窗口下面的错误.......请帮我在这...红宝石无法连接到Postgresql

development: 
    adapter: postgresql 
    encoding: unicode 
    database: my db name 
    username: user name 
    password: password 
    host: host name 

test: 
    adapter: postgresql 
    database: db_pchamara 
    database: my db name 
    username: user name 
    password: password 
    host: host name 
    pool: 5 


production: 
    adapter: postgresql 
    database: my db name 
    username: user name 
    password: password 
    host: host name 
    pool: 5 

,但如果我运行命令“轨服务器”在终端它显示了以下错误。

Started GET "/assets/rails.png" for 127.0.0.1 at 2012-12-05 18:10:51 +0530 

ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished): 
    activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection' 
    activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection' 
    activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection' 
    activerecord (3.2.9) lib/active_record/query_cache.rb:67:in `rescue in call' 
    activerecord (3.2.9) lib/active_record/query_cache.rb:61:in `call' 
    activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call' 
    actionpack (3.2.9) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call' 
    activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `_run__189673354__call__558944823__callbacks' 
    activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `__run_callback' 
    activesupport (3.2.9) lib/active_support/callbacks.rb:385:in `_run_call_callbacks' 
    activesupport (3.2.9) lib/active_support/callbacks.rb:81:in `run_callbacks' 
    actionpack (3.2.9) lib/action_dispatch/middleware/callbacks.rb:27:in `call' 
    actionpack (3.2.9) lib/action_dispatch/middleware/reloader.rb:65:in `call' 
    actionpack (3.2.9) lib/action_dispatch/middleware/remote_ip.rb:31:in `call' 
    actionpack (3.2.9) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call' 
    actionpack (3.2.9) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' 
    railties (3.2.9) lib/rails/rack/logger.rb:32:in `call_app' 
    railties (3.2.9) lib/rails/rack/logger.rb:16:in `block in call' 
    activesupport (3.2.9) lib/active_support/tagged_logging.rb:22:in `tagged' 
    railties (3.2.9) lib/rails/rack/logger.rb:16:in `call' 
    actionpack (3.2.9) lib/action_dispatch/middleware/request_id.rb:22:in `call' 
    rack (1.4.1) lib/rack/methodoverride.rb:21:in `call' 
    rack (1.4.1) lib/rack/runtime.rb:17:in `call' 
    activesupport (3.2.9) lib/active_support/cache/strategy/local_cache.rb:72:in `call' 
    rack (1.4.1) lib/rack/lock.rb:15:in `call' 
    actionpack (3.2.9) lib/action_dispatch/middleware/static.rb:62:in `call' 
    railties (3.2.9) lib/rails/engine.rb:479:in `call' 
    railties (3.2.9) lib/rails/application.rb:223:in `call' 
    rack (1.4.1) lib/rack/content_length.rb:14:in `call' 
    railties (3.2.9) lib/rails/rack/log_tailer.rb:17:in `call' 
    rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service' 
    /usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service' 
    /usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run' 
    /usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread' 


    Rendered /usr/local/rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.2ms) 
    Rendered /usr/local/rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.6ms) 
    Rendered /usr/local/rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (13.3ms) 
+0

尝试使用psql连接到数据库:'psql -h'localhost'--username'user_name''database_name''。如果它的工作原理,问题是在RoR上,而不是在PostgreSQL – macool

+0

是啊..该命令工作正常亚.. ..它在终端控制台上运行 –

回答

1

您是否在您的Gemfile中设置了gem'pg'?

检查你的Gemfile,请确保您的评论(或删除)宝石sqlite的,并确保您列出了

gem 'pg' 

宝石PG,运行bundle命令(将设置的库,它开始之前,你的应用程序将加载):

bundle 

检查文件Gemfile.lock的,确保创业板PG被列出。

一旦你完成了所有这一切,要确保你实际上是在你的PostgreSQL服务器创建一个数据库:

bundle exec rake db:create 

和公正的情况下,运行任何挂起的迁移

bundle exec rake db:migrate 
+0

先生如果我运行命令束它不列出postgres宝石..我试图' bundle show postgres'..但没有用 –

+0

你不需要“postgres”宝石,你需要“pg”宝石。你是否在我的答案中写过Gemfile上的宝石“pg”?如果你这样做,当你运行命令“bundle”时,你应该看到类似“Using pg(0.14.1)”的东西,并且为了确保你有gem,由bundle生成的文件被称为“Gemfile.lock “你可以看到你的应用程序依赖的所有宝石。所以你可以运行“grep pg Gemfile.lock”,你应该看到pg gem,如果它不在那里,那么你的Gemfile出现了问题,请按照我的说明再试一次。 Thx – rorra

+0

先生,我试图通过使用'gem install pg'来安装pg gem。它运行,它显示宝石已成功安装和ri文件也创建..但是当我运行捆绑它没有显示那里和一件事最初我卸载sqlite3宝石,但是当我运行该包时,sqlite3宝石会自动获取安装..如何与这位先生一起来? –

0

如果这可以帮助,我database.yml如下:

development: 
    adapter: postgresql 
    encoding: utf8 
    reconnect: false 
    database: kenyu_dev 
    pool: 5 
    username: kenyu 
    password: super_secret_pass 
    host: localhost 

而且,做了哟你创建用户并给他正确的权限?尝试以用户身份登录psql

+0

是否有必要在测试和生产中给予编码? –

+0

我是数据库的超级用户..我可以通过psql命令登录到postgres ... butis显示相同的错误 –