最新 Rails 3:ActionView::Template::Error(无法解析第 105 行第 13 列的 YAML)
我最近在 Rails 3 中遇到了一个奇怪的问题,可能是自从新的 rubygems 1.5 更新以来。基本上,当我使用乘客 3.0.2 将程序部署到 nginx 时,我立即有 500 个页面,并且在我的生产日志中出现如下问题:
ActionView::Template::Error (couldn't parse YAML at line 105 column 13):
10: </div>
11: <% end %>
12: <div class="field">
13: <%= f.label :name %> <%= f.text_field :name %>
14: </div>
15: <div class="field">
16: <%= f.label :password %> <%= f.password_field :password %>
app/views/sessions/new.html.erb:13:in `block in _app_views_sessions_new_html_erb___4159562374589718885_19217640_4456777064017176818'
app/views/sessions/new.html.erb:5:in `_app_views_sessions_new_html_erb___4159562374589718885_19217640_4456777064017176818'
看起来环境中缺少某些内容,因此它无法识别我的所有 form_for 元素。基本上,该页面只是一个简单的登录页面,有 2 个字段 - 名称和密码。其他带有表单的页面也会出现此问题,但仅限于生产环境。在开发环境中,它完全工作正常。我已经将所有gems升级到最新版本,包括rails 3.0.4,但是看起来与这个问题不太相关。在 gem 1.5 之前,我也曾经在我的 VMware 上的 ubuntu 上部署过同样的东西,现在一切都还好,但是新的部署已经没有回头路了。
我已经将其部署到两台运行最新ubuntu的机器上,两台机器都有这样的错误。 Nginx 和乘客按照标准步骤安装。显然,由于这个问题,该网站永远无法运行。任何人都可以为此提供任何错误修复吗?如果可以的话非常感谢!
PS:我写的登录页面基本上来自这里: http://railstutorial.org/chapters/sign-in-sign-out#top
I have recently encountered into a weird problem or Rails 3, possibly ever since the new rubygems 1.5 update. Basically when I deploy my program to nginx with passenger 3.0.2, I have 500 page immediately and problems like this in my production log:
ActionView::Template::Error (couldn't parse YAML at line 105 column 13):
10: </div>
11: <% end %>
12: <div class="field">
13: <%= f.label :name %> <%= f.text_field :name %>
14: </div>
15: <div class="field">
16: <%= f.label :password %> <%= f.password_field :password %>
app/views/sessions/new.html.erb:13:in `block in _app_views_sessions_new_html_erb___4159562374589718885_19217640_4456777064017176818'
app/views/sessions/new.html.erb:5:in `_app_views_sessions_new_html_erb___4159562374589718885_19217640_4456777064017176818'
It looks like it's missing something in the environment and so it can't recognize all of my form_for elements. Basically the page is just a simple login page with 2 fields - name and password. This problem also happens for other pages with forms, but only in production environment. In development environment, it's totally working fine. I have upgraded all my gems to the latest version, including rails 3.0.4, which however looks like not quite related to this problem. I also used to deploy the same thing onto the ubuntu on my VMware BEFORE gem 1.5, everything is still fine now, however there's no turning back for the new deployments.
I have deployed this to 2 machines running latest ubuntu, and both machine have such errors. Nginx and passenger are installed with the standard steps. Obviously with this problem the site can never run. Can anyone provide any bug fix for this? Thanks very much if you could!
PS: the login page I wrote is basically from here:
http://railstutorial.org/chapters/sign-in-sign-out#top
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将以下两行添加到 config/boot.rb 文件中,问题得到解决。
I added the following two lines to the config/boot.rb file and the problem was solved.
我也有同样的问题。实际上我只需要第一行:
不需要专门设置 YAML::Engine。
I had the same problem. Actually I only needed the first line:
No need to set the YAML::Engine specifically.
对于 yaml 语法问题,TextMate 中的“查看/显示不可见项”等选项可能非常有助于定位语法问题,yaml 对此非常敏感。
就我而言,我只需将所有语言环境文件中的所有制表符替换为空格即可。
另请注意,如果同一级别上没有同名的节点。
For a problems with yaml syntax options like 'View/Show invisibles' in TextMate may be very helpful to locate syntax problems, yaml is very sensitive about it.
In my case I just had to replace all tabs with spaces in all locale files.
Also notice, if you don't have nodes with the same name on same level.