Ruby-on-rails Rails 未解析有效的 YAML 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11741799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rails not parsing a valid YAML file
提问by Bart Platak
I'm trying to parse the following YAML with my Rails (3.2.7) application
我正在尝试使用 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
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 Lintand apparently the YAML code is valid. What's causes this?
我是 Rails(和 YAML)的新手,但是我已经使用YAML Lint检查了代码,显然 YAML 代码是有效的。这是什么原因造成的?
采纳答案by lucas clemente
Try
尝试
main-menu:
- mitem: Test1
controller: user
action: test
- mitem: Test
controller: user
action: test2
children:
- mitem: Test3
controller: user
action: test
回答by Komra Moriko
The first best thing to do is run your yaml file through http://yamllint.com/
最好的第一件事是通过http://yamlint.com/运行您的 yaml 文件
回答by axsuul
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
回答by Irfan Ahmad
Check in your YAML you must have any extra or less spaces before a key value,this helped me.
检查您的 YAML,您必须在键值之前有任何额外或更少的空格,这对我有帮助。

