Rails load YAML to hash and reference by symbol

前端 未结 11 2286
慢半拍i
慢半拍i 2021-02-01 12:22

I am loading a YAML file in Rails 3.0.9 like this:

APP_CONFIG = YAML.load(File.read(File.expand_path(\'../app.yml\', __FILE__)))

It loads the a

11条回答
  •  天命终不由人
    2021-02-01 12:26

    There is another potential answer I discovered while digging around.

    You can forgo HashWithIndifferentAccess.new by instead adding this to the top of your YAML files:

    --- !map:HashWithIndifferentAccess
    

    then simply YAML.load like normal. The only trick is that rails needs to already be loaded if you are doing this in your environment for use in initializers, etc. (like I am).

提交回复
热议问题