I'm trying to parse the following YAML with my Rails (3.2.7) application
---
main-menu:
- mitem: Test1
controller: user
action: test
- mitem: Test
controller: user
action: test2
- mitem: Test3
controller: user
action: test
Unfortunately straight when I load my file
require "yaml"
@menu = YAML.load_file(file)
I get an error
Psych::SyntaxError in User#test
Showing /srv/http/fiss/app/views/layouts/application.html.haml where line #12 raised:
(/srv/http/fiss/app/assets/yaml/menu.yaml): did not find expected key while parsing a block mapping at line 6 column 5
I'm new to Rails (and YAML), however I have checked the code with YAML Lint and apparently the YAML code is valid. What's causes this?
The first best thing to do is run your yaml file through http://yamllint.com/
Try
main-menu:
- mitem: Test1
controller: user
action: test
- mitem: Test
controller: user
action: test2
children:
- mitem: Test3
controller: user
action: test
You have an indent issue. Do you mean
main-menu:
- mitem: Test1
controller: user
action: test
- mitem: Test
controller: user
action: test2
- mitem: Test3
controller: user
action: test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With