繁体   English   中英

我无法在Rails中获得refile.rb fron setting.yml的值

[英]I can't get the value of refile.rb fron setting.yml in rails

我想在config / initializers / refile.rb中调用setting.yml的值,所以我尝试如下设置。

当我运行SPEC文件时,Refile.cdn_host的值为空。 我不太清楚为什么这个值是空的。 我可以得到一些建议吗?

配置/设置/ test.yml

cloudfront:
 host: 'localhost'

配置/初始化/ refile.rb

Refile.cdn_host = Settings.cloudfront.host

顺便说一下,当我如下更改时,

Refile.cdn_host = 'localhost'

它的工作原理不为空。

您需要先加载文件,然后尝试

Refile.cdn_host = YAML.load_file("#{Rails.root.to_s}/config/settings/test.yml")['cloudfront']['host']

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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