[英]Requesting a ruby-on-rails application gives Psych::BadAlias error
I ran the rails server from my application directory. 我从应用程序目录运行了Rails服务器。 But when I tried to do a request from the browser with
但是当我尝试从浏览器发出请求时
http://localhost:3000
I get the following error: 我收到以下错误:
*Psych::BadAlias * Psych :: BadAlias
Cannot load Rails.application.database_configuration
: Unknown alias: default* 无法加载
Rails.application.database_configuration
:未知别名:默认*
This happens because the ruby-plugin for netbeans messes the database.yml file when creating project from existing source. 发生这种情况是因为从现有源创建项目时,netbeans的ruby插件使database.yml文件混乱。 It replaces the comment about sqlite3 to mysql, but even worse it erases the first definition block which is 'default'
它将有关sqlite3的注释替换为mysql,但更糟糕的是,它删除了第一个定义块,即“默认”
So simply insert 所以只需插入
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
at the beginning of the database.yml and you'll be fine 在database.yml的开头,就可以了
This is being caused by an invalid alias in your database.yml
file. 这是由于您的
database.yml
文件中的别名无效引起的。 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. 在此,
&defaults
定义您的错误正在谈论的别名。 Make your database.yml
look more like this syntax and you should be set. 使您的
database.yml
看起来更像这种语法,应进行设置。 Or, post your database.yml
file here and we can help you fix it specifically if needed. 或者,在此处发布您的
database.yml
文件,我们可以在需要时帮助您专门修复它。
The content of the database.yml file is: database.yml文件的内容为:
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: 我使用netbeans作为文本编辑器,并且文件顶部显示错误,指示:
ComposerException null we had this found undefined alias default ComposerException null我们找到了默认未定义别名
Thank you 谢谢
您可能需要升级红宝石> 1.9。
发生这种情况是因为如果您使用rbenv-vars插件,则密码DB具有某些特殊字符,请更改密码而无需特殊字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.