rails 3, how use an ENV config vars in a Settings.yml file?

前端 未结 4 2001
野的像风
野的像风 2020-12-25 11:22

In my settings.yml file I have several config vars, some of which reference ENV[] variables.

for example I have ENV[\'FOOVAR\'] equals WIDGET

I thought I cou

4条回答
  •  萌比男神i
    2020-12-25 11:45

    I was able to resolve this with simple code

    data = {}
    YAML.load_file("path_of_file/settings.yml").each do |key, value|
      data[key] = ENV[value] || value
    end 
    

    where my data was something like this

    account: ACCOUNT_USERNAME
    password: ACCOUNT_PASSWORD
    port: 5002
    

    and ACCOUNT_USERNAME and ACCOUNT_PASSWORD are environment variables

提交回复
热议问题