Rails没有解析有效的YAML文件

Bar*_*tak 8 yaml web-applications ruby-on-rails

我正在尝试使用我的Rails(3.2.7)应用程序解析以下YAML

---
main-menu:
  - mitem: Test1
    controller: user
    action: test
  - mitem: Test
    controller: user
    action: test2
    - mitem: Test3
      controller: user
      action: test
Run Code Online (Sandbox Code Playgroud)

不幸的是,当我加载我的文件时

    require "yaml"
    @menu = YAML.load_file(file)
Run Code Online (Sandbox Code Playgroud)

我收到一个错误

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
Run Code Online (Sandbox Code Playgroud)

我是Rails(和YAML)的新手,但是我已经用YAML Lint检查了代码,显然YAML代码是有效的.这是什么原因造成的?

小智 27

首先要做的是通过http://yamllint.com/运行你的yaml文件


luc*_*nte 7

尝试

main-menu:
  - mitem: Test1
    controller: user
    action: test
  - mitem: Test
    controller: user
    action: test2
    children:
      - mitem: Test3
        controller: user
        action: test
Run Code Online (Sandbox Code Playgroud)