【发布时间】:2011-09-03 16:52:58
【问题描述】:
我刚刚将我在 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.
但是“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
非常感谢您的帮助!
【问题讨论】:
-
我直接在 heroku 上编译资产,不会用编译的资产污染我的本地存储库。使用命令:heroku run rake assets:precompile
标签: ruby-on-rails heroku ruby-on-rails-3.1 web-deployment