简体   繁体   中英

Requesting a ruby-on-rails application gives Psych::BadAlias error

I ran the rails server from my application directory. But when I tried to do a request from the browser with

http://localhost:3000

I get the following error:

*Psych::BadAlias

Cannot load Rails.application.database_configuration : Unknown alias: default*

This happens because the ruby-plugin for netbeans messes the database.yml file when creating project from existing source. It replaces the comment about sqlite3 to mysql, but even worse it erases the first definition block which is 'default'

So simply insert

default: &default
adapter: sqlite3
pool: 5
timeout: 5000

at the beginning of the database.yml and you'll be fine

This is being caused by an invalid alias in your database.yml file. You most likely have something that looks close to this... but not quite:

defaults: &defaults
  adapter:  mysql2
  username: root
  password: 
  host:     localhost
  timeout:  5000

development:
  database: app_name_development
  <<: *defaults

In this, &defaults defines the alias that your error is talking about. Make your database.yml look more like this syntax and you should be set. Or, post your database.yml file here and we can help you fix it specifically if needed.

The content of the database.yml file is:

development:
  <<: *default
  database: db/development.sqlite3
test:
  <<: *default
  database: db/development.sqlite3_test

production:
  <<: *default
  database: db/development.sqlite3_production

I am using netbeans as text editor and there is a error at the top of the file indicating:

ComposerException null we had this found undefined alias default

Thank you

您可能需要升级红宝石> 1.9。

发生这种情况是因为如果您使用rbenv-vars插件,则密码DB具有某些特殊字符,请更改密码而无需特殊字符。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM