我在Heroku托管的Ruby on Rails 3.2.13应用程序中遇到了一个奇怪的错误,我无法在本地复制,我无法确定原因。
以下是症状:
在几个页面上,我看到了可怕的“我们很抱歉,但出了点问题”错误:
日志表明存在模板错误:
Started GET "/users/sign_in" for 107.203.222.41 at 2013-05-27 13:45:18 +0000
ActionView::Template::Error (syntax error on line 6, col 15: `'):
15: <%= f.password_field :password %></div>
16:
21: <div><%= f.submit "Sign in" %></div>
19: <% end -%>
17: <% if devise_mapping.rememberable? -%>
18: <div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
app/views/devise/sessions/new.html.erb:8:in `_app_views_devise_sessions_new_html_erb__2053461519121638579_44147620'
app/views/devise/sessions/new.html.erb:18:in `block in _app_views_devise_sessions_new_html_erb__2053461519121638579_44147620'
20:
注意行号是如何乱序的。
以下是另一页的示例:
Started GET "/blog" for 107.203.222.41 at 2013-05-27 13:36:10 +0000
ActionView::Template::Error (syntax error on line 6, col 15: `'):
10: <%= render :partial => "post", :collection => @posts %>
13: <% end %>
9: <%= content_tag(:div, :id => 'blog_content') do %>
11:
12: <%= will_paginate @posts, :page_links => false %>
14:
15: <%= render 'sidebar' %>
app/views/posts/blog.html.erb:12:in `block (2 levels) in _app_views_posts_blog_html_erb___3437273290190956225_40741600'
app/views/posts/blog.html.erb:9:in `block in _app_views_posts_blog_html_erb___3437273290190956225_40741600'
app/views/posts/blog.html.erb:7:in `_app_views_posts_blog_html_erb___3437273290190956225_40741600'
知道什么会导致此错误吗?如何确切地确定“第6行,第15列”指的是什么?
非常感谢!
修改
这对我来说没有任何意义,但这是导致问题的原因:
<% if devise_mapping.rememberable? -%>
<div>
<%= f.check_box :remember_me %>
<%#= f.label :remember_me %>
</div>
<% end -%>
如果我注释掉f.label行,页面加载正常。如果我取消注释它,我会得到语法错误。会导致这种情况的原因是什么?
编辑2
我从头开始重新创建文件并输入代码的相关部分:
<%= form_for(resource, :as => resource_name, :url => session_url(resource_name), :autocomplete => 'off') do |f| %>
<div>
<%= f.check_box :remember_me %>
<%#= f.label :remember_me %>
</div>
<% end %>
同样的问题:当评论f.label行时,页面加载。当它被取消注释时,我得到相同的语法错误:
ActionView::Template::Error (syntax error on line 6, col 15: `')
答案 0 :(得分:1)
原来这是en.yml中YAML的一个问题。
具体来说,YAML最初是:
# Sample localization file for English. Add more files in this directory for other locales.
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
en:
activerecord:
models:
attributes:
如果您将其插入http://yamllint.com/之类的内容,则会收到我在生产日志中看到的错误消息:
syntax error on line 6, col 15: `'
将此更改回Rails默认修复了问题:
# Sample localization file for English. Add more files in this directory for other locales.
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
en:
hello: "Hello world"
此线程有更多关于Rails中YAML解析的信息,这使我找出原因:rails error, couldn't parse YAML