我正在阅读基本的rails教程,当我尝试使用“rails s”运行我的服务器时 我在localhost:3000浏览器中获得ActiveRecord :: ConnectionNotEstablished。
我在教程中告诉我确保我的database.yml具有正确的凭据但不是 告诉如何做到这一点。我正在使用Postgresql。这就是我的databse.yml:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: postgresql
database: myrubyblog
username:postgres
password: theoffice
pool: 5
timeout: 5000
host: localhost
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: postgresql
database: myrubyblog
username:postgres
password: theoffice
pool: 5
timeout: 5000
host: localhost
production:
adapter: postgresql
database: myrubyblog
username:postgres
password: theoffice
pool: 5
timeout: 5000
host: localhost
谢谢!
答案 0 :(得分:1)
尝试删除行:
pool: 5
timeout: 5000
host: localhost
再次尝试启动服务器
如果它仍然失败。确保你已正确安装psql
$ sudo -u postgres psql
> CREATE ROLE "Blou91" PASSWORD 'secret' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;
如果你收到像'Sucsses'这样的消息。将database.yml更改为:
common: &common
adapter: postgresql
username: "Blou91"
password: "secret"
development:
<<: *common
database: myrubyblog_development
test:
<<: *common
database: myrubyblog_test
production:
<<: *common
database: myrubyblog_production
然后在rails应用程序目录下运行
$ bundle exec rake db:create db:migrate