Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

postgresql - Rails: No connection pool for 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.

What could it be?

EDIT

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.

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.

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you are experiencing this error from a rake task, chances are you are not running the :environment task before your task.

Changing:

task :task_name do
end

to:

task task_name: :environment do
end

Should fix the issue.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...