在Heroku上更新到Rails 3.1时的资产管道 [英] Assets pipeline when updating to Rails 3.1 on Heroku
问题描述
我刚刚将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提供了一个assets:precompile rake任务允许在每次请求资产时付清编制罚款。如果此任务存在于您的应用程序中,我们将在您推送新代码时执行此任务。
但是应该如何处理assets:precompile任务?我试图用rails 3.1从头开始构建一个项目来试图找出问题,但在裸露的项目中没有这样的任务。或者我错过了什么?我怎么能让这些资产在缓存中找到?也许只是配置问题。
这些是我的配置文件的选项:
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = true#如果关闭此功能,我会得到一个500错误,并且日志会说:资产未编译
我的application.rb包含以下行:
config.assets.enabled = true
感谢您的帮助!
我想知道同样的事情,但这里有一个提示,您的资产是否实时编译
- 运行
rake资产:预编译
本地 - 对css进行一些更改,但不重新运行rake任务
- git添加,提交并推送到heroku
如果您在步骤2中所做的更改显示在heroku上,则您知道您的应用现场编译
不要忘记,您现在负责http缓存,因为Varnish不再包含在青瓷中,所以您需要设置rack-cache和memcached自己:
- heroku doc http caching
- 设置 rack-cache 在heroku上使用memcached
- heroku docs on memcached
但是,发现这也令人费解
I've just upgraded my app on Heroku from Rails 3.0 to 3.1, and I'm trying to make the assets pipeline work. The main issue is that I can read from the heroku log the following kind of lines, for every asset:
2011-09-03T16:35:28+00:00 app[web.1]: cache: [GET /assets/border-a3c571a354b9381740db48aeebfaa63a.jpg] miss
If I understand the pipeline correctly, this should not be "miss" for every request I make from a browser, but it should be found in the cache.
Reading the Heroku docs you can find this explanation:
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.
But how should that "assets:precompile" task be? I tried building a project with rails 3.1 from scratch to try to find out, but there is no such task in a bare project. Or am I missing something? How could I make that the assets are found in the cache? Maybe is just an issue with configuration.
These are the options of my production config file:
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
My application.rb has this line:
config.assets.enabled = true
Thanks a lot for your help!
解决方案I was wondering the same thing, but here's a tip to help figure out if your assets are live-compiling or not
- run
rake assets:precompile
locally - make some changes to your css but do not rerun the rake task
- git add, commit and push to heroku
If the changes you made in step 2 show up on heroku, then you know your app is live-compiling
Don't forget that you are now in charge of http caching since Varnish is no longer included on celadon, so you need to set up rack-cache and memcached yourself:
- heroku doc on http caching
- setup rack-cache with memcached on heroku
- heroku docs on memcached
But yeah, I found this puzzling too
这篇关于在Heroku上更新到Rails 3.1时的资产管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- heroku docs on memcached