Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails not parsing a valid YAML file

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?

like image 442
Bart Platak Avatar asked Jul 31 '12 13:07

Bart Platak


3 Answers

The first best thing to do is run your yaml file through http://yamllint.com/

like image 152
Komra Moriko Avatar answered Nov 16 '22 10:11

Komra Moriko


Try

main-menu:
  - mitem: Test1
    controller: user
    action: test
  - mitem: Test
    controller: user
    action: test2
    children:
      - mitem: Test3
        controller: user
        action: test
like image 7
lucas clemente Avatar answered Nov 16 '22 10:11

lucas clemente


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
like image 2
axsuul Avatar answered Nov 16 '22 09:11

axsuul