全局常量不使用正确的值更新

时间:2015-05-15 23:08:18

标签: ruby-on-rails ruby

在Rails 4中,我有一个config / config.yml,我想与config / secrets.yml分开。我更新了配置以包含twilio信息:

development:
  sendgrid:
    username: username
    password: password
    domain: domain
  twilio:
    account_sid: account_sid
    auth_token: auth_token
    twilio_number: twilio_number

在config / application.rb中,我加载了全局常量(我无法在初始化程序中加载它,因为我需要在环境中使用它/ * rb并在初始化程序之前加载环境/ * rb)。这是全局常量:

module RailsDevise
  class Application < Rails::Application
    ...
    config.before_configuration do
      ::APP_CONFIG = YAML.load_file("#{Rails.root}/config/config.yml")[Rails.env]
    end
  end
end

加载控制台时,不会反映更改:

> APP_CONFIG
 => {"sendgrid"=>{"username"=>"username", "password"=>"password", "domain"=>"domain"}, "twilio"=>{"account_sid"=>"account_sid", "auth_token"=>"auth_token"}} 

然而,肯定他们在那里:

> YAML.load(File.open("#{Rails.root}/config/config.yml"))
{"development"=>{"sendgrid"=>{"username"=>"username", "password"=>"password", "domain"=>"domain"}, "twilio"=>{"account_sid"=>"account_sid", "auth_token"=>"auth_token", "twilio_number"=>"twilio_number"}}

可以进行什么样的缓存?我多次重新加载控制台,它应该重新加载整个应用程序。但它没有检测到yml文件中的更改。

2 个答案:

答案 0 :(得分:5)

sync不会影响您自己的rails console,但会springspring基本上在后台运行并使您的应用程序驻留在内存中以更快地启动(重新)rails console或运行测试等。它检测文件更改并重新启动,但它无法监视所有内容,并且绝对不会监视您自己的自定义YAML配置文件中的更改。运行spring将准确描述您的症状,它是默认Gemfile的一部分。

当这些事情再次发生时:spring stop然后再试一次。

答案 1 :(得分:0)

我正在使用Rails 5,但遇到了同样的问题,清除了缓存。

rake tmp:cache:clear