我刚刚将我的Heroku应用程序从Rails 3.0升级到3.1,并且正在尝试使资产管道正常工作。主要问题是我可以从Heroku日志中读取每个资产的以下类型行:
2011-09-03T16:35:28+00:00 app[web.1]: cache: [GET /assets/border-a3c571a354b9381740db48aeebfaa63a.jpg] miss
如果我正确理解了pipeline,那么每次从浏览器发出请求时,这个应该不会“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.
但是,"assets:precompile"任务应该如何执行?我尝试从头开始构建一个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
非常感谢你的帮助!