2
I have installed ruby 1.9.3-p327, and my databse is postgres.I modified the database.yml page also..as:evelopment:

适配器:postgresql 数据库:db_pchamar 用户名:db_test_user 密码:密码主机:192.168.1.101 池:5

测试:适配器:postgresql 数据库:db_pchamara.test 用户名:db_test_user 密码:密码主机:192.168.1.101 池:5

生产:适配器:postgresql 数据库:db_pchamara 用户名:db_test_user 密码:密码主机:192.168.1.101 池:5 .但是我遇到的问题是,当我运行rails server它时显示以下错误:它没有连接到 postgre db..

但是如果运行 ruby​​ 文件,它会从 db 获取数据:帮我解决这个问题,.....

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__241814793__call__597619238__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.4ms)
  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 (0.9ms)
  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 (9.6ms)



This is my gemfile.lock

Gems included by the bundle:
  * actionmailer (3.2.9)
  * actionpack (3.2.9)
  * activemodel (3.2.9)
  * activerecord (3.2.9)
  * activeresource (3.2.9)
  * activesupport (3.2.9)
  * arel (3.0.2)
  * builder (3.0.4)
  * bundler (1.2.3)
  * coffee-rails (3.2.2)
  * coffee-script (2.2.0)
  * coffee-script-source (1.4.0)
  * erubis (2.7.0)
  * execjs (1.4.0)
  * hike (1.2.1)
  * i18n (0.6.1)
  * journey (1.0.4)
  * jquery-rails (2.1.4)
  * json (1.7.5)
  * mail (2.4.4)
  * mime-types (1.19)
  * multi_json (1.4.0)
  * pg (0.14.1)
  * polyglot (0.3.3)
  * rack (1.4.1)
  * rack-cache (1.2)
  * rack-ssl (1.3.2)
  * rack-test (0.6.2)
  * rails (3.2.9)
  * railties (3.2.9)
  * rake (10.0.2)
  * rdoc (3.12)
  * sass (3.2.3)
  * sass-rails (3.2.5)
  * sprockets (2.2.2)
  * thor (0.16.0)
  * tilt (1.3.3)
  * treetop (1.4.12)
  * tzinfo (0.3.35)
  * uglifier (1.3.0)
4

2 回答 2

2

检查位于应用程序目录根目录中的 Gemfile。

删除 gem 'sqlite' 并添加 gem 'pg' 然后保存。运行捆绑安装

安装 gems 的最佳方法是将它们添加到 gem 文件中并运行 bundle install。不推荐运行“gem install -”

您还需要修改位于 config 文件夹中的 database.yml 并进行必要的调整以运行 pg。

于 2012-12-04T18:45:34.460 回答
1

如果您遇到此类错误,您必须检查三个文件..

1.database.yml 2. postgresql 库中的 pg_hba.conf。3. 如果你在远程机器上工作,我们还必须将我们的主机 ip 包含到 database.yml 文件中......

在创建项目时,使用他的命令向服务器了解您将使用 postgresql ..

'rails 新演示 --database=postgresql'

那么只有 pg gem 文件会被加载到 bundle..

将 pg_hba.conf 文件编辑为信任的 md5 文件。它将在您的 IP 地址附近。

md5- 需要密码才能连接到 db trust- 不要询问密码

确保您的 database.yml 文件正确

于 2012-12-08T08:02:23.270 回答