2025-10-30 06:14PM
我在启动 ruby on rails 项目的时候报错了:
root@8461e6951fbe:/opt/app# bundle exec rails s -p 9903 -b 0.0.0.0
/opt/app/config/application.rb:9: warning: already initialized constant OpenSSL::SSL::VERIFY_PEER
/usr/local/bundle/gems/psych-5.2.6/lib/psych/visitors/to_ruby.rb:471:in `visit_Psych_Nodes_Alias': Alias parsing was not enabled. To enable it, pass `aliases: true` to `Psych::load` or `Psych::safe_load`. (Psych::AliasesNotEnabled)
from /usr/local/bundle/gems/psych-5.2.6/lib/psych/visitors/visitor.rb:30:in `visit'
from /usr/local/bundle/gems/psych-5.2.6/lib/psych/visitors/visitor.rb:6:in `accept'
from /usr/local/bundle/gems/psych-5.2.6/lib/psych/visitors/to_ruby.rb:35:in `accept'
from /usr/local/bundle/gems/psych-5.2.6/lib/psych/visitors/to_ruby.rb:386:in `block in revive_hash'
from /usr/local/bundle/gems/psych-5.2.6/lib/psych/visitors/to_ruby.rb:384:in `each'
from /usr/local/bundle/gems/psych-5.2.6/lib/psych/visitors/to_ruby.rb:384:in `each_slice'
主要原因是因为:Rails 项目中某个 YAML 配置文件使用了 YAML 别名语法(如 &alias 定义别名、*alias 引用别名),但当前 Psych 库(Ruby 处理 YAML 的默认库)默认禁用了别名解析功能。
例如:
config/database.yml 文件
default: &default
adapter: mysql2
encoding: utf8
collation: utf8_general_ci
pool: 5
host: localhost
username: root
password: 111111
development:
<<: *default
database: okt
test:
<<: *default
database: okt_test
production:
<<: *default
url: 'mysql2://root:@localhost:3306/coiex?pool=10&timeout=3000'
pool: 10
database: okt
不能使用 &default 和 *default
所以修改后的内容如下:
development:
adapter: mysql2
encoding: utf8
collation: utf8_general_ci
pool: 5
host: localhost
username: root
password: 111111
database: okt
test:
adapter: mysql2
encoding: utf8
collation: utf8_general_ci
pool: 5
host: localhost
username: root
password: 111111
database: okt_test
production:
adapter: mysql2
encoding: utf8
collation: utf8_general_ci
pool: 10
host: localhost
username: root
password: 111111
database: okt
如果还报错,那就是其他文件还有,没有修改完,全部修完就不会报错了
登录
请登录后再发表评论。
评论列表:
目前还没有人发表评论