【问题标题】:"We're sorry, but something went wrong." after deployment to Heroku“我们很抱歉,但有些不对劲。”部署到 Heroku 后
【发布时间】:2011-12-12 01:12:05
【问题描述】:

我制作了一个小应用程序,用户可以在其中登录/注销、创建等等。我使用 mySQL 作为数据库,并且在本地环境中一切正常。但是在我将它部署到heroku并迁移数据库等之后,heroku版本不起作用。当我跟踪日志时,我得到了这个:

2011-10-20T18:48:22+00:00 app[web.1]: Started GET "/" for 83.233.57.240 at 2011-10-20 11:48:22 -0700
2011-10-20T18:48:22+00:00 app[web.1]:   Processing by HomeController#index as HTML
2011-10-20T18:48:22+00:00 app[web.1]: Rendered home/index.html.erb within layouts/application (0.0ms)
2011-10-20T18:48:22+00:00 app[web.1]: Completed 500 Internal Server Error in 2ms
2011-10-20T18:48:22+00:00 app[web.1]: 
2011-10-20T18:48:22+00:00 app[web.1]: ActionView::Template::Error (defaults.js isn't precompiled):
2011-10-20T18:48:22+00:00 app[web.1]:     3:   <head>
2011-10-20T18:48:22+00:00 app[web.1]:     4:     <title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
2011-10-20T18:48:22+00:00 app[web.1]:     5:     <%= stylesheet_link_tag "application" %>
2011-10-20T18:48:22+00:00 heroku[router]: GET afternoon-lightning-2154.heroku.com/ dyno=web.1 queue=0 wait=0ms service=7ms status=500 bytes=728
2011-10-20T18:48:22+00:00 app[web.1]:     6:     <%= javascript_include_tag :defaults %>
2011-10-20T18:48:22+00:00 app[web.1]:     7:     <%= csrf_meta_tag %>
2011-10-20T18:48:22+00:00 app[web.1]:     8:     <%= yield(:head) %>
2011-10-20T18:48:22+00:00 app[web.1]:     9:   </head>
2011-10-20T18:48:22+00:00 app[web.1]:   app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___2280146998680186378_39052620'
2011-10-20T18:48:22+00:00 app[web.1]: 
2011-10-20T18:48:22+00:00 app[web.1]: 
2011-10-20T18:48:22+00:00 app[web.1]: cache: [GET /] miss

我可以看到它在某个时候完成了 500 错误,但我不知道为什么。对此有什么建议吗?提前致谢!

【问题讨论】:

    标签: mysql ruby-on-rails ruby git heroku


    【解决方案1】:

    检查你在 config/environments/production 中有这个

    # Fallback to assets pipeline if a precompiled asset is missed
    config.assets.compile = true
    

    基本上你的问题是你的资产没有被自动编译。

    更多信息在这里:http://devcenter.heroku.com/articles/rails31_heroku_cedar

    编辑:

    从 Rails 3.1 开始,我们将使用资产管道。这意味着您需要将所有资产(图像、javascript、css)放在app/assets 中。在 3.1 之前,将把这些放在 public/**/* 中。

    在开发模式下,Rails 3.1 将自动编译(缩小 JS 和 CSS,在某些情况下将图像转换为 base64 等)所有资产,创建一个小的版本化包。

    举个实际例子,在你的项目中运行bundle exec rake assets:precompile。查看public/ 中的新文件夹。之后您可以安全地删除它。

    在生产模式下,这不是自动的。您可以启用资产的自动编译,也可以在部署前手动运行bundle exec rake assets:precompile

    有关资产管道的更多信息 http://guides.rubyonrails.org/asset_pipeline.html

    有用:https://github.com/dnagir/guard-rails-assets

    【讨论】:

    • Beautifull....实际上已经尝试过一次,但没有成功。我第二次这样做时,它确实有效。你能告诉我它实际上是做什么的吗?非常感谢。
    • 你在开玩笑......你刚刚也修复了我的 css 问题!由于某种原因,它似乎没有拿起 css,但它有助于编译它。我应该每次进行更改时都这样做还是一次性的?
    • 您的应用将使用 public/*.如果它在那里没有找到资产,那么如果 config.assets.compile = true 它将重新编译所有资产。如果该选项为假,那么它将抛出一个异常,指出它没有找到资产。所以是的,每次您的资产更改时,您都需要手动重新编译。但是如果你有 config.assets.compile = true 那么那根本就没有必要。
    • 另外,请检查您在 conf/application.rb 上是否有 config.assets.compile = true
    • bundle exec rake assets:precompile 在部署工作之前。
    猜你喜欢
    • 2016-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-30
    • 2012-05-17
    • 1970-01-01
    • 2011-12-01
    • 1970-01-01
    相关资源
    最近更新 更多