没有ActiveRecord :: Base的连接池 [英] No connection pool for ActiveRecord::Base
问题描述
我正在尝试使用Rails 4.2.6开发应用程序。我正在尝试将postgres用于数据库。服务器启动正常,但是当我尝试加载页面时,它将引发此 ActiveRecord :: Base没有连接池错误。
I'm trying to use rails 4.2.6 to develop an app. I'm trying to use postgres for database. Server starts fine but when I try loading a page it throws this "No connection pool for ActiveRecord::Base" error.
那会是什么?
编辑
pg宝石无法正常工作。在启动服务器之前,我必须先对其进行评论,然后再从我的GemFile中将其取消注释。我意识到我使用的是Ruby 2.3而不是Ruby 2.0(按预期)。我删除了ruby 2.3,并在ruby 2.0环境下设置了所有内容。
The pg gem wasn't working properly. I had to comment it before starting the server and then uncomment it from my GemFile afterwards. I realized that I was using Ruby 2.3 instead of Ruby 2.0 (as intended). I removed ruby 2.3 and set up everything under ruby 2.0 environment. It's now working properly.
我在某个地方读到,在较新的Rails版本中 pg gem存在一些问题,要求人们使用 gem install pg。 pre'代替安装gem。我尝试了一下,但是随后我的应用程序在我的GemFile中要求使用 pg gem,而且,上述问题再次出现。
I had read somewhere that there were some issues with the 'pg' gem in newer Rails releases, requiring people to use 'gem install pg --pre' instead for installing the gem. I tried that, but then my app was requiring the 'pg' gem in my GemFile and, well, the problem stated above showed up again.
这是我的database.yml文件结束的方式:
This is how my database.yml file ended up:
default: &default
adapter: postgresql
encoding: unicode
host: localhost
username: -------
password: -------
pool: 5
development:
<<: *default
database: myDbName
推荐答案
如果您在rake任务中遇到此错误,则可能是您没有运行 :environment
任务之前。
If you are experiencing this error from a rake task, chances are you are not running the :environment
task before your task.
更改:
task :task_name do
end
至:
task task_name: :environment do
end
应解决此问题。
这篇关于没有ActiveRecord :: Base的连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!