【问题标题】:Can a YML file access another YML file?一个 YML 文件可以访问另一个 YML 文件吗?
【发布时间】:2012-01-23 23:30:22
【问题描述】:

我们有一个站点范围的config.yml 文件,它与 api 密钥等联系...

我的另一个 YML 文件可以访问 config.yml 中的值吗?

config.yml:

development:
    thing: 123123123123

plugin_config.yml:

development:
    thing: config.yml.development.thing

这可能吗?

【问题讨论】:

标签: ruby-on-rails ruby-on-rails-3 yaml


【解决方案1】:

你总是可以用 ERB 解析它:

development:
    thing: 123123123123

development:
    thing: <%= YAML.load(ERB.new(File.read(Rails.root.join('config','config.yml'))).result)['development'] %>

然后加载第一个并用 ERB 解析它(在初始化程序或其他东西中):

CONFIG = YAML.load(ERB.new(File.read(Rails.root.join('config','plugin_config.yml'))).result)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    • 1970-01-01
    • 1970-01-01
    • 2011-03-15
    • 1970-01-01
    • 2012-05-01
    相关资源
    最近更新 更多