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.
但是“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
非常感谢您的帮助!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
另外,请查看 http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets
Also, take a look at http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets
我想知道同样的事情,但这里有一个提示可以帮助确定您的资产是否实时编译或未
rake assets:precompile
如果您在步骤 2 中所做的更改显示在 heroku 上,那么您就知道您的应用程序正在实时编译
不要忘记您现在负责 http 缓存自从清漆不再包含在 celadon 中,因此您需要自己设置rack-cache 和 memcached:
但是,是的,我也发现这令人困惑
I was wondering the same thing, but here's a tip to help figure out if your assets are live-compiling or not
rake assets:precompile
locallyIf 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:
But yeah, I found this puzzling too
您可以尝试将
config.serve_static_assets
设置为true
并将其添加到您的
config/environments/production.rb
文件中吗?当您将代码推送到 Heroku 时,您应该会看到 slug 编译器 AFAICT 宣布的预编译。
Can you try with
config.serve_static_assets
set totrue
andadded to your
config/environments/production.rb
file?When you push your code to Heroku you should see the precompiling announced by the slug compiler AFAICT.
确保您位于 Heroku“Cedar” 堆栈。然后Heroku 将在 slug 编译期间自动预编译您的资源。
注意:我仍然遇到“缓存未命中”问题,但我认为这不是真的,因为如果您的资产未编译,您的应用程序将无法工作。
Make sure you are on the Heroku "Cedar" stack. Then Heroku will automatically precompile your assets during slug compilation.
Note: I'm still getting "cache misses" too, but I don't think that's really true because your app wouldn't work if your assets weren't compiled.