Rails:没有 ActiveRecord::Base 的连接池 [英] Rails: No connection pool for ActiveRecord::Base

查看:13
本文介绍了Rails:没有 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 gem 工作不正常.我必须在启动服务器之前对其进行评论,然后在我的 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

应该解决问题.

这篇关于Rails:没有 ActiveRecord::Base 的连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆