简体   繁体   English

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

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

I would like to call value of setting.yml in config/initializers/refile.rb So I try to set it as follows.But it Does not work as I thought. 我想在config / initializers / refile.rb中调用setting.yml的值,所以我尝试如下设置。

When I run SPEC file, the value of Refile.cdn_host is empty. 当我运行SPEC文件时,Refile.cdn_host的值为空。 I don't know well why this value is empty. 我不太清楚为什么这个值是空的。 can I get some advice? 我可以得到一些建议吗?

config/settings/test.yml 配置/设置/ test.yml

cloudfront:
 host: 'localhost'

config/initializers/refile.rb 配置/初始化/ refile.rb

Refile.cdn_host = Settings.cloudfront.host

Incidentally when I change it as follows, 顺便说一下,当我如下更改时,

Refile.cdn_host = 'localhost'

it does work without being empty. 它的工作原理不为空。

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

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