【问题标题】:Heroku error: we're sorry something went wrong, check application logs - syntax errorHeroku 错误:很抱歉出了点问题,请检查应用程序日志 - 语法错误
【发布时间】:2015-08-11 20:26:45
【问题描述】:

将我的 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,我仍然得到这个错误。此代码在开发模式下按原样工作,没有语法错误。有什么想法/帮助吗?

【问题讨论】:

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


    【解决方案1】:

    正如错误所说,您的哈希中有语法错误:

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

    特别是,当这些键包含连字符时,您不能使用附加的: 定义符号哈希键。 (无论环境如何,这都应该是正确的,因为它是一个 Ruby 语法问题,所以你对它在开发中工作的评论很奇怪。)相反,你必须使用旧的 =&gt; 定义这些哈希键值对:

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

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

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

    但是,这不适用于任意的连字符属性。

    【讨论】:

    • 谢谢,解决了这个问题,但是在开发模式没有这些变化的情况下它可以工作,谁能解释为什么?
    • 你确定吗?它不是有效的 Ruby。也许您正在加载不同的代码?确保没有缓存任何内容...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-22
    • 2012-05-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多