在Heroku上更新到Rails 3.1时的资产管道

我刚刚将我在Heroku上的应用程序从Rails 3.0升级到3.1,并且我正在努力使资产管道工作。 主要问题是我可以从heroku日志中读取以下类型的行,用于每个资产:

2011-09-03T16:35:28+00:00 app[web.1]: cache: [GET /assets/border-a3c571a354b9381740db48aeebfaa63a.jpg] miss 

如果我正确理解了管道,那么对于我从浏览器发出的每个请求,都不应该“错过”,但应该在缓存中找到它。

阅读Heroku文档,您可以找到以下解释:

 Rails 3.1 provides an assets:precompile rake task to allow the compilation penalty to be paid up front rather than each time the asset is requested. If this task exists in your app we will execute it when you push new code. 

但是,“资产:预编译”任务应该如何? 我尝试从头开始使用rails 3.1构建一个项目以试图找出,但在裸项目中没有这样的任务。 或者我错过了什么? 我怎么能让资产在缓存中找到? 也许只是配置问题。

这些是我的生产配置文件的选项:

 config.serve_static_assets = false config.assets.compress = true config.assets.compile = true # If I turn this off I get a 500 error and logs say that an asset isn't compiled 

我的application.rb有这一行:

 config.assets.enabled = true 

非常感谢你的帮助!

我想知道同样的事情,但这里有一个提示,以帮助弄清楚你的资产是否是实时编译

  1. 运行rake assets:precompile在本地rake assets:precompile
  2. 对您的CSS进行一些更改但不要重新运行rake任务
  3. git add,commit和push to heroku

如果您在第2步中所做的更改显示在heroku上,那么您就知道您的应用是实时编译的

不要忘记您现在负责http缓存,因为Varnish不再包含在青瓷中,因此您需要自己设置rack-cache和memcached:

  • http缓存上的heroku doc
  • 在heroku上使用memcached设置机架缓存
  • memcached上的 heroku文档

但是,我发现这也令人费解

另外,请查看http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets

对于更快的资产预编译,您可以通过在config / application.rb中将config.assets.initialize_on_precompile设置为false来部分加载应用程序,但在这种情况下,模板无法查看应用程序对象或方法。 Heroku要求这是假的

您可以尝试将config.serve_static_assets设置为true

 config.action_dispatch.x_sendfile_header = "X-Sendfile" 

添加到您的config/environments/production.rb文件?

当您将代码推送到Heroku时,您应该看到slug编译器AFAICT宣布的预编译。

确保你在Heroku“Cedar”堆栈上 。 然后Heroku将在slug编译期间自动预编译您的资产 。

注意:我仍然会收到“缓存未命中”,但我不认为这是真的,因为如果您的资产未编译,您的应用程序将无法运行。