YAML with erb is not parsing

后端 未结 1 968

Why this yaml file won\'t parse?

---
<% sensor_types = YAML.load_file(\'db/seed-fixtures/sensor_type.yml\') %>
<% sensor_types.each do |sensor_type|         


        
相关标签:
1条回答
  • 2021-01-08 00:26

    You can't load a YAML file containing ERB like a basic YAML file. Checkout this post.

    What you can do instead is (in a spec initializer or a before hook):

    FIXTURE_CONFIG = YAML.load(ERB.new(File.read("#{Rails.root}/path_to_your_file.yml.erb")).result)
    

    And then use this variable in your test.

    0 讨论(0)
提交回复
热议问题