简体   繁体   中英

How to generate .yml file from Ruby on Rails?

I would like generate the following result in a.yml file from Ruby on Rails:

include:
  - template: ./my_folder/my_file.txt

But I am generating the following result with single quote (''):

include:
- 'template: ./my_folder/my_file.txt'

I have tried generate the.yml file with this ruby code:

my_variable = {"include" => ["template: ./my_folder/my_file.txt"]}

I would do this:

my_variable = { "include" => [{ "template" => "./my_folder/my_file.txt" }] }
my_variable.to_yaml
# ---
# include:                                
# - template: "./my_folder/my_file.txt"   
my_variable = {"include" => ["template: ./my_folder/my_file.txt"]}
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The Array contains a String, not a Hash. It will produce a YAML array with a single string value, not an array with a key/value pair.

Either you have a typo in your data, or you need to split the values in the Array on : to produce a Hash.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM