【问题标题】:Heroku static assetsHeroku 静态资产
【发布时间】:2013-05-11 15:01:29
【问题描述】:

在 Heroku 上,我收到 at=error code=H10 desc="App crashed" method=GET path=/favicon.ico 路由错误。

在本地,我收到ActionController::RoutingError (No route matches [GET] "/favicon.ico"): 路由错误。

我通过将config.serve_static_assets = 设置为TRUE 并运行rake assets:precompile 来解决本地问题。

我一直无法解决 Heroku 上的问题。我推送了更新版本,跑heroku run rake assets:precompile无济于事。

这让我发疯了......一个缩略图图标站在我和成功部署之间。任何建议将不胜感激!

完整的heroku日志转储:

2013-05-11T17:08:14.869656+00:00 heroku[web.1]: State changed from crashed to starting
2013-05-11T17:08:16.053848+00:00 heroku[web.1]: Starting process with command `bundle exec rails server -p 44239`
2013-05-11T17:08:18.803969+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
2013-05-11T17:08:18.804053+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
2013-05-11T17:08:20.523845+00:00 app[web.1]: => Booting WEBrick
2013-05-11T17:08:20.524082+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
2013-05-11T17:08:20.524082+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
2013-05-11T17:08:20.523845+00:00 app[web.1]: => Call with -d to detach
2013-05-11T17:08:20.523845+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:312:in `depend_on'
2013-05-11T17:08:20.524353+00:00 app[web.1]:    from /app/config/environment.rb:5:in `<top (required)>'
2013-05-11T17:08:20.523845+00:00 app[web.1]: => Rails 3.2.13 application starting in production on http://0.0.0.0:44239
2013-05-11T17:08:20.524082+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/engine.rb:438:in `block in eager_load!'
2013-05-11T17:08:20.524353+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
2013-05-11T17:08:20.523845+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:317:in `rescue in depend_on': No such file to load -- Digest (LoadError)
2013-05-11T17:08:20.524082+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
....
2013-05-11T17:08:21.668731+00:00 heroku[web.1]: State changed from starting to crashed

更新 天哪,这都是由于 require 'Digest' 的大写字母 'D' ... 小写并且一切正常。那是我生命中的几个小时,我再也回不来了。

【问题讨论】:

  • 如果你把 favicon.ico 放到公用文件夹会怎样?
  • 它在我的公共文件夹中

标签: ruby-on-rails ruby heroku production-environment


【解决方案1】:

当您设置 - config.serve_static_assets = false 并尝试执行 bundle exec rake assets:precompile RAILS_ENV=production 时会发生什么?此外,以下config.assets.compile 设置为true

我注意到您将favicon 放在您的公共目录中。我可以通过在layouts/application.html.erb 中执行以下操作来设置我的网站图标

<!DOCTYPE html>
<html>
    <head>
        <title><%= home_title %></title>
        <%= stylesheet_link_tag "application" %>
        <%= javascript_include_tag "application" %>
        <%= csrf_meta_tag %>
        <link rel="icon" href="<%= image_path 'icon.ico' %>" type="image/ico" />
        <link rel="shortcut icon" href="<%= image_path 'icon.ico' %>" type="image/ico" />
    </head>

你会注意到我的icon.ico。我的 icon.ico 在我的 app/assets/images 目录中。

【讨论】:

  • 不喜欢设置为 false 并进行 rake。 config.assets.compile 设置为 FALSE。我为图标链接复制/粘贴了您的 html,并将文件移动到 app/assets/images ... 不高兴。
  • @DanShev 您刚刚说您将 config.assets.compile 设置为 FALSE,而最初您说 config.serve_static_assets = 为 TRUE。我认为您可能只是将错误的内容设置为 false。默认情况下,您的 config.assets.compile 应设置为 true。为了清理我的environments/production.rb 看起来像下面这样,你的也应该如此。 gist.github.com/anonymous/5560804。我有什么然后运行bundle exec rake assets:precompile RAILS_ENV=production,还包括我的html。如果它给你一个错误粘贴在这里