我在 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: `')