Heroku错误:我们很遗憾出了问题,检查应用程序日志 - 语法错误

时间:2015-08-11 20:26:46

标签: ruby-on-rails heroku deployment syntax erb

将rails应用程序部署到heroku时,会出现以下错误:

We're sorry, but something went wrong.
If you are the application owner check the logs for more information.

我用:

检查了日志
 heroku logs 

它显示了很多语法错误:

2015-08-11T20:11:57.266169+00:00 app[web.1]: /app/app/views/users/index.html.erb:50: syntax error, unexpected '}', expecting keyword_end
2015-08-11T20:11:57.266171+00:00 app[web.1]: ...'data-target': "#modal-window"} do@output_buffer.safe_append...
2015-08-11T20:11:57.266173+00:00 app[web.1]: ...                               ^
2015-08-11T20:11:57.266175+00:00 app[web.1]: /app/app/views/users/index.html.erb:53: syntax error, unexpected keyword_else, expecting keyword_end
2015-08-11T20:11:57.266218+00:00 app[web.1]: /app/app/views/users/index.html.erb:55: syntax error, unexpected ':', expecting =>
2015-08-11T20:11:57.266220+00:00 app[web.1]: ...                 'data-toggle':"modal", 'data-target': "#mod...
2015-08-11T20:11:57.266221+00:00 app[web.1]: ...                               ^
2015-08-11T20:11:57.266223+00:00 app[web.1]: /app/app/views/users/index.html.erb:55: syntax error, unexpected ',', expecting keyword_end
2015-08-11T20:11:57.266225+00:00 app[web.1]: ...         'data-toggle':"modal", 'data-target': "#modal-windo...
2015-08-11T20:11:57.266226+00:00 app[web.1]: ...                               ^
2015-08-11T20:11:57.266228+00:00 app[web.1]: /app/app/views/users/index.html.erb:55: syntax error, unexpected ':', expecting keyword_end
2015-08-11T20:11:57.266229+00:00 app[web.1]: ...toggle':"modal", 'data-target': "#modal-window", class: "sta...

但是,在我的开发模式中,我没有语法错误,一切正常。

以下是给出语法错误的代码部分:

 <div class="tab-pane fade in active" id="allposts">
                <%current_user.friends.each do |x|%>
                  <%x.posts.order(created_at: :desc).each do |y|%>
                    <div class="panel panel-info">
                      <div class="panel-heading">
                        <%=y.created_at.strftime("%b %d %Y")%>
                        <span id="time">
                          <%=y.created_at.strftime("%l:%M%P")%>
                        </span>
                      </div>
                      <div class="panel-body">
                        <div class="row">
                          <div class="col-md-3">
                            <%=link_to user_profile_path(x) do%>
                            <%=image_tag(x.profile_picture.url, class: 'feedprofilepic')%><br>
                            <span>
                              <%=y.user.email%>
                            </span>
                            <%end%>
                          </div>
                          <div class="col-md-9">
                            <%if y.type=="Image"%> ***(LINE 50 HERE)***

                              <!-- link_to can accept block, this will make whole picture containing div a link -->
                              <%=link_to post_path(y), {remote:true, 'data-toggle': "modal", 'data-target': "#modal-window"} do%>
                                  <%=image_tag(y.body.url, :style=>'max-width:100%;max-height:100%;')%>
                              <%end%><br>
                            <%else%>
                              <%=link_to post_path(y), {remote:true,
                              'data-toggle':"modal", 'data-target': "#modal-window", class: "statuslink"} do%>
                                <h2>
                                  <div class="status">
                                    <%=y.body%>
                                  </div>
                                </h2>
                              <%end%>
                            <%end%>
                          </div>
                        </div>

在Chrome中,开发工具我得到500错误

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

注意:我在生产环境中安装了rails 12 factor gem,我仍然会收到此错误。此代码在开发模式下工作,没有语法错误。有什么想法/帮助吗?

1 个答案:

答案 0 :(得分:0)

如错误所示,您的哈希中存在语法错误:

{remote:true, 'data-toggle':"modal", 'data-target': "#modal-window", class: "statuslink"}

特别是,当这些键包含连字符时,您无法使用附加的:定义符号哈希键。 (由于它是一个Ruby语法问题,因此无论环境如何都应该如此,因此您在开发中使用它的注释很奇怪。)相反,您必须使用旧的=>来定义这些哈希键值对:

{remote:true, class: "statuslink", :'data-toggle' => "modal", :'data-target' => "#modal-window"}

请注意,Rails还支持使用嵌套哈希定义data-*属性:

{remote:true, class: "statuslink", data: {toggle: "modal", target: "#modal-window"}}

但是,对于任意带连字符的属性,这不起作用。