2

我正在学习一个基本的 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

谢谢!

4

1 回答 1

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

于 2013-10-04T07:35:20.030 回答