【问题标题】:Heroku "We're sorry, but something went wrong." due to javascript_include_tagHeroku “我们很抱歉,但出了点问题。”由于 javascript_include_tag
【发布时间】:2013-06-13 00:47:28
【问题描述】:

将我的 ruby​​ on rails 应用程序上传到 heroku 会导致以下错误:

很抱歉,出了点问题。

这不会发生在我的本地机器上。

经过一些调试,我想我可能已经发现了错误,但不知道如何修复它。

在我的文件 application.html.erb 中,删除以下行解决了问题,但随后我的应用程序丢失了它的 jquery 移动主题。有什么想法可以解决这个问题吗?

导致问题的线路:

<%= javascript_include_tag "application" %>

application.html.erb 文件:

<!DOCTYPE html>
<html>
<head>
  <title>Washapp</title>
  <meta name="viewport" content="width=device-width">
  <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
  <%= javascript_include_tag "application" %>

  <script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
  <%= csrf_meta_tags %>

  <script>
    if (window.location.hash == "#_=_")
        window.location.hash = "";
  </script>

</head>
<body>
  <div data-role="page">
    <%= yield %>
  </div>
</body>
</html>

Heroku 日志:

2012-04-08T23:28:41+00:00 heroku[nginx]: 78.105.51.57 - - [08/Apr/2012:23:28:41 +0000] "GET / HTTP/1.1" 500 643 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.151 Safari/535.19" washappdelete2.heroku.com
2012-04-08T23:28:43+00:00 app[web.1]: 
2012-04-08T23:28:43+00:00 app[web.1]: Started GET "/" for 78.105.51.57 at 2012-04-08 16:28:43 -0700
2012-04-08T23:28:43+00:00 app[web.1]: 
2012-04-08T23:28:43+00:00 app[web.1]: Processing by HomeController#index as HTML
2012-04-08T23:28:43+00:00 app[web.1]:   Rendered home/routa_list.html.erb within layouts/application (0.1ms)
2012-04-08T23:28:43+00:00 app[web.1]: Completed 500 Internal Server Error in 34ms
2012-04-08T23:28:43+00:00 app[web.1]: 
2012-04-08T23:28:43+00:00 app[web.1]:     4:   <title>Washapp</title>
2012-04-08T23:28:43+00:00 app[web.1]: ActionView::Template::Error (application.js isn't precompiled):
2012-04-08T23:28:43+00:00 app[web.1]:     5:   <meta name="viewport" content="width=device-width">
2012-04-08T23:28:43+00:00 app[web.1]:     6:   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
2012-04-08T23:28:43+00:00 app[web.1]:     7:   <%= javascript_include_tag "application" %>
2012-04-08T23:28:43+00:00 app[web.1]:     9:   <script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
2012-04-08T23:28:43+00:00 app[web.1]:     8:   
2012-04-08T23:28:43+00:00 app[web.1]:     10:   <%= csrf_meta_tags %>
2012-04-08T23:28:43+00:00 app[web.1]:   app/views/layouts/application.html.erb:7:in `_app_views_layouts_application_html_erb__2373145142857118006_42724320'
2012-04-08T23:28:43+00:00 app[web.1]:   app/controllers/home_controller.rb:4:in `index'
2012-04-08T23:28:43+00:00 app[web.1]: cache: [GET /] miss
2012-04-08T23:28:43+00:00 app[web.1]: 
2012-04-08T23:28:43+00:00 app[web.1]:

app/assets/javascripts/application.js

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require_tree .

存储库https://github.com/karangb/herokuProblem

【问题讨论】:

  • 您使用的是什么版本的导轨?可能与资产管道有关。根据您所处的环境,包含的资产会有所不同。guides.rubyonrails.org/asset_pipeline.html
  • 我正在运行 Rails 3.2.2
  • 是的,这与您的资产编译有关。阅读我发布的链接。
  • 如果你不知道heroku logs 可能会有用
  • 你的意思是 app/assets/javascripts/application.js?我刚刚用它更新了我的帖子

标签: javascript ruby-on-rails jquery-mobile heroku


【解决方案1】:

问题解决了!

很简单——取自500 internal server error when I try to push my app onto Heroku

因此,根据您提供的 heroku 信息,我发现您正在使用 竹栈,该栈不支持 Rails 3.1+。只有 cedar 堆栈支持 Rails 3.1+。您需要使用以下内容 在 cedar 堆栈上创建新应用的命令:

heroku create --stack cedar

【讨论】:

  • 所以最终唯一能解决这个问题的人要么是你,要么是 Heroku。 Sigh 至少这篇文章将服务于一个很好的全方位目的。我建议,如果您发现我们的大部分回复很有用,请给予适当的信任。
  • 是的,很遗憾。花了几个小时 - 希望heroku日志更好。非常感谢。这里提供的支持鼓励我继续前进! :)
  • 耶,拯救了这一天,卡兰!只需将 .git/config 中的 url 更改为 [remote "heroku"] 部分,然后重新运行 git push heroku masterheroku run rake db:migrate...
【解决方案2】:

在 config/application.rb 中,添加

config.assets.initialize_on_precompile = false

然后推送到 git,然后是 heroku 推送。

【讨论】:

    【解决方案3】:

    尝试添加

    //= require jquery.mobile

    在你的

    app/assets/stylesheets/application.js

    amd 设置

    config.assets.compile = tue

    在你的

    config/enviroments/production.rb

    【讨论】:

    • 如果这不起作用,请将app/assets中的文件和文件夹的名称添加到您的问题中
    • 实际上您可能必须使用 gem "jquery-mobile-rails" 才能完成这项工作。
    • 这不起作用......我将添加 gem - (顺便说一句,我在 heroku 日志中有一些无法找到 Javascript 运行时......)。添加gem后我会更新
    • 添加gem不起作用...添加gem后是否必须修改application.html.erb文件?
    • 是的,你不应该再手动包含 jquery javascript 文件了。
    【解决方案4】:

    尝试在 config/enviroments/production.rb 中将以下行设置为 false:

    config.assets.compile = false
    

    【讨论】:

    • hmm...该行已经在我的 production.rb 中-我之前可能已经添加了它...仍然导致错误...
    • 你的 application.js 文件的内容是什么?
    • //= 需要 jquery //= 需要 jquery_ujs //= 需要_tree .
    • 也许您需要将 jquery.mobile-1.0.1.min.js 下载到您的 assets/javascripts 目录...然后它会被预编译?尽量不要在外部引用它(但这只是一个猜测......)
    • 我已将我的源代码添加到 github。请注意,最后几个 cmets 很糟糕! github.com/karangb/herokuProblem
    【解决方案5】:

    如果你在app/assets 中有类似 java 的东西,这会抛出链轮。将其命名为类似 applet 将允许编译 javascripts 目录的内容。 Source

    【讨论】:

    • 我认为我的应用程序/资产中没有类似 java 的东西。我有 - 图片 --- rails.png - javascripts --- application.js --- home.js.coffee --- users.js.coffee - 样式表 --- application.css --- home.css.scss --- 脚手架.css.scss --- users.css.scss
    【解决方案6】:

    你也在设置吗

    config.assets.initialize_on_precompile = false
    

    这是 Rails 3.2 的新变化(请参阅Docs

    不过,你应该能够在 slug 编译期间看到一个错误(如下例,如果你没有设置上面的标志)

    -----> Preparing app for Rails asset pipeline
           Running: rake assets:precompile
           rake aborted!
           could not connect to server: Connection refused
           Is the server running on host "127.0.0.1" and accepting
           TCP/IP connections on port 5432?
    

    您也可以尝试在本地运行 rake 预编译任务,然后查看错误(再次,正如文档所建议的那样)。

    【讨论】:

    • 那么您是否尝试rake assets:precompile 看看您是否在本地遇到问题?
    【解决方案7】:

    确保没有未跟踪的文件,请执行git status

    也许可以试试,heroku run rake db:migrate

    【讨论】:

      猜你喜欢
      • 2012-07-29
      • 2012-04-19
      • 2012-06-19
      • 1970-01-01
      • 1970-01-01
      • 2014-01-22
      • 1970-01-01
      • 2011-12-01
      • 2014-10-15
      相关资源
      最近更新 更多