几天后就从rails和Linux开始......我想部署到heroku,其中一个最佳实践是无论如何也要在本地环境中使用postgresql......我遵循了其中一个教程并创建了一个示例应用程序
安装了 pg gem。捆绑安装工作正常。rake db:migrate
工作并为我的应用程序创建了表。但是......当我尝试运行我的rails页面时,它给出了这个错误:
ActiveRecord::ConnectionNotEstablished
这是完整跟踪的结尾:
> activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `retrieve_connection'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
activerecord (3.2.3) lib/active_record/query_cache.rb:67:in `rescue in call'
activerecord (3.2.3) lib/active_record/query_cache.rb:61:in `call'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:467:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `_run__4423031206660944571__call__1711406629982304701__callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
我正在使用 pgadmin 3 来查看我的数据库。我创建了一个名为 schaller 的用户,它与我在 Ubuntu 中的用户相同
我的 database.yml 文件:
development:
adapter: postgresql
database: rails
encoding: unicode
username: schaller
password: password123
host: localhost
pool: 5
为了让rails连接到postgres,我还能检查什么?
编辑:
在 webrick 上的 netbeans 中启动 rails 服务器时出错
在 2012-09-13 23:12:31 +0300 ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished) 开始 GET "/gangs/" for 127.0.0.1: activerecord (3.2.3) lib/active_record/connection_adapters/abstract /connection_pool .rb:398:in
retrieve_connection' activerecord (3.2.3) lib/active_record/connection_adapters/abstract /connection_specification.rb:168:in
retrieve_connection' activerecord (3.2.3) lib/active_record/connection_adapters/abstract /connection_specification.rb:142:inconnection' activerecord (3.2.3) lib/active_record/query_cache.rb:67:in
rescue in call' ...
编辑我的 gem 文件中的主要内容:
gem 'rails', '3.2.3'
gem 'pg'
gem 'thin'
编辑:为 postgresql 连接添加日志
[local]
2012-09-15 18:05:35 IDT LOG: connection received: host=127.0.0.1 port=44038
2012-09-15 18:05:35 IDT LOG: connection authorized: user=schaller database=postgres
2012-09-15 18:05:35 IDT LOG: connection received: host=127.0.0.1 port=44039
2012-09-15 18:05:35 IDT LOG: connection authorized: user=schaller database=rails
2012-09-15 18:07:26 IDT LOG: connection received: host=127.0.0.1 port=44048
2012-09-15 18:07:26 IDT LOG: connection authorized: user=schaller database=rails
无论如何,当我连接 pgadmin 3 并运行命令“rake db:migrate”时,我看到正在写入日志,但当我运行我的 rails 应用程序时却没有……
谢谢