Rails no analiza un archivo YAML válido

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)

Me sale un 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?

preguntado el 31 de julio de 12 a las 14:07

4 Respuestas

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

Respondido 19 Jul 13, 19:07

I second the above. Online YAML Parser found an error a few lines down from where I was getting the "did not find expected key while parsing a block..." error. - movimiento profundo

Trata

main-menu:
  - mitem: Test1
    controller: user
    action: test
  - mitem: Test
    controller: user
    action: test2
    children:
      - mitem: Test3
        controller: user
        action: test

Respondido 31 Jul 12, 16:07

Thanks that solved the issue.. Rather peculiar tho; I have also tested it with python and likewise Ruby my original version doesn't work. Is this just because of YAML syntax? - Bart Platak

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

Respondido 31 Jul 12, 16:07

Sorry I wasn't explicit with my question. This indentation is purposeful - I'm trying to allow for a mitem tener sub-mitems (and so on, recursively) - Bart Platak

the indentation is purposeful? blank spaces are meaningful? - Gianluca Guettini

Check in your YAML you must have any extra or less spaces before a key value,this helped me.

Respondido el 03 de junio de 16 a las 02:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.