0

我已经做了一切:

宝石文件:

gem 'rails_12factor', group: :production

配置/环境/production.rb

config.serve_static_assets = true

配置/应用程序.rb

config.assets.precompile += %w( *.css *.js )

我在 vendor/assets/ 下有我的 js 和 css 文件。当我部署到 heroku 时,一切看起来都很好:

Running: rake assets:precompile
Asset precompilation completed (310.44s)

当我看到 application-5c84e59d83c00fd13fb659edc18db24a.js 和 application-cb9661f49811aa5c8d103e83ee8747b2.css 时,它们是空的

我究竟做错了什么 ?

我读过了:

Heroku 不会在 Rails 4 中的资产管道下编译文件

尝试了几个修复:Heroku/Rails 4 Assets Precompile Error

4

3 回答 3

1

我相信我找到了根本原因问题。我选择将其发布为新答案,因为它与我在上面发布的解决方法是分开的。

我构建并部署了一个空的新 Rails 4 应用程序(这很有效)。通过比较production.rb文件,我注意到非工作应用程序中有这样一行:

# Specifies the header that your server uses for sending files
# (comment out if your front-end server doesn't support this)
config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx

此配置行在新的 rails 4 应用程序中被注释掉。Heroku 文档建议这样做:

config.action_dispatch.x_sendfile_header = nil # For Heroku

当我改变它时,一切都按预期工作。

于 2013-09-01T20:11:49.270 回答
0

This is not the "real" solution, but Heroku will compile assets at runtime. See this guide.

Of course, by default in production, your view renders any asset_paths generated through helpers (e.g. image_tag() or styleheet_link_tag(), or asset_path() within your SASS, etc) with a digest, which would normally grab the appropriate precompiled file.

But this is broken, so you can turn this off, and let rails compile assets at runtime. This is obviously much less performant, but if your only goal is to get your site working right now, this should work.

In production.rb:

  config.assets.digest = false

Then your stylesheet link should resolve to something like /assets/application.css, which should work (it did in my app). But, again, this isn't the real solution but rather a work-around. If you make any traction on the actual root cause, let me know.

于 2013-09-01T19:35:54.697 回答
0

您可以通过将以下内容显式添加到 application.rb 来解决此问题

# config/application.rb

config.assets.paths << Rails.root.join('vendor', 'assets')

似乎尽管 Rails 确切地知道它想要什么,但 Heroku 需要提醒将资产文件夹包含在资产路径中。

于 2014-11-11T00:47:37.990 回答