2017-06-22 29 views
0

我想在config/initializers/refile.rb中調用setting.yml的值因此,我嘗試將其設置爲如下所示。但它沒有按我的想法工作。我無法在rails中獲得refile.rb fron setting.yml的值

當我運行SPEC文件時,Refile.cdn_host的值爲空。 我不太清楚爲什麼這個值是空的。 我可以得到一些建議嗎?

配置/設置/ test.yml

cloudfront: 
host: 'localhost' 

配置/初始化/ refile.rb

Refile.cdn_host = Settings.cloudfront.host 

順便說一句,當我更改如下,

Refile.cdn_host = 'localhost' 

它的工作而不是空的。

回答

0

您需要首先加載該文件,嘗試

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