Saya ingin tahu cara mem-parsing file YAML dengan konten berikut:
---
javascripts:
- fo_global:
- lazyload-min
- holla-min
Saat ini saya mencoba menguraikannya dengan cara ini:
@custom_asset_packages_yml = (File.exists?("#{RAILS_ROOT}/config/asset_packages.yml") ? YAML.load_file("#{RAILS_ROOT}/config/asset_packages.yml") : nil)
if !@custom_asset_packages_yml.nil?
@custom_asset_packages_yml['javascripts'].each{ |js|
js['fo_global'].each{ |script|
script
}
}
end
Tapi sepertinya tidak berfungsi dan memberi saya kesalahan bahwa nilainya nol.
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
Jika saya mencoba ini, ia mengeluarkan seluruh string (fo_globallazyload-minholla-min):
if !@custom_asset_packages_yml.nil?
@custom_asset_packages_yml['javascripts'].each{ |js|
js['fo_global']
}
end