我正在尝试运行初始化脚本来帮助我从config.yml文件中检索数据。
config.yml目前看起来像这样:
production: &default
log_server: log_server
deploy_to: /path/to/deploy
unicorn:
port: 8080
uid: user
gid: group
development: &dev
<<: *default
deploy_to:path/to/deploy
unicorn:
port: 80
uid: unicorn
gid: unicorngroup
这是我到目前为止的config.rb文件:
require 'yaml'
require 'erb'
config = YAML.load(ERB.new(File.read("/Users/NguyenC/gomoto_server/config/api_settings.yml")).result)
如果我'put config',输出如下:
{"production"=>{"log_server"=>"log_server", "deploy_to"=>"path/to/deploy", "unicorn"=>{"port"=>8080, "uid"=>"user", "gid"=>"group"}}, "development"=>{"log_server"=>"log_server", "deploy_to"=>"path/to/deploy", "unicorn"=>{"port"=>80, "uid"=>"unicorn", "gid"=>"unicorn group"}}
如果我想从生产或开发中获取某些变量,我怎么称呼变量?我的目标是能够根据我使用的Env调用任何变量。