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

alv*_*tar 5 ruby-on-rails heroku web-deployment ruby-on-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
Run Code Online (Sandbox Code Playgroud)

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

阅读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.
Run Code Online (Sandbox Code Playgroud)

但是,"资产:预编译"任务应该如何?我尝试从头开始使用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
Run Code Online (Sandbox Code Playgroud)

我的application.rb有这一行:

config.assets.enabled = true
Run Code Online (Sandbox Code Playgroud)

非常感谢你的帮助!

小智 5

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

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


ste*_*och 4

我也想知道同样的事情,但这里有一个提示可以帮助确定您的资产是否是实时编译的

  1. rake assets:precompile本地运行
  2. 对 CSS 进行一些更改,但不要重新运行 rake 任务
  3. git add、提交并推送到heroku

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

不要忘记你现在负责http缓存,因为Celadon中不再包含Varnish,所以你需要自己设置rack-cache和memcached:

但是,是的,我也发现这令人困惑