2011-09-03 68 views
5

我刚刚将Heroku中的应用从Rails 3.0升级到3.1,并试图使资产管道工作。主要的问题是,我可以阅读从Heroku的日志中的以下样线,对每一项资产:在Heroku上更新到Rails 3.1时的资产管道

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. 

但是应该怎样说,“资产:预编译”的任务是什么?我试图用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 

非常感谢您的帮助!

+0

我直接编译在Heroku上的资产,不会产生污染我的本地库与compliled资产。 使用命令:heroku运行rake资产:预编译 –

回答

4

我想知道同样的事情,但这里有一个技巧,以帮助找出如果你的资产是活编译或不

  1. 运行rake assets:precompile本地
  2. 做出一些改变你的CSS,但不重新运行rake任务
  3. git的添加,提交和推到Heroku的

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

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

  • 设置rack-cache

    • Heroku的文档与memcached的在Heroku
    • Heroku的文档上memcached

    但是,是的,我发现这太令人费解

  • +0

    谢谢你的回答,它充满了重要的信息。 – alvatar

    1

    你能与config.serve_static_assets设置为true

    config.action_dispatch.x_sendfile_header = "X-Sendfile" 
    

    尝试添加到您的config/environments/production.rb文件?

    当您将代码推送到Heroku时,您应该看到slug编译器AFAICT宣布的预编译。

    +0

    “----->准备Rails资产管道的应用程序”出现,但也是如此。尽管如此,仍然得到缓存未命中...... – alvatar

    +0

    它不应该使用ngnix指令吗? 'config.action_dispatch.x_sendfile_header ='X-Accel-Redirect'' – tibbon

    1

    确保您在Heroku "Cedar" stack。然后Heroku will automatically precompile your assets during slug compilation

    注意:我仍然在“缓存未命中”,但我不认为这是真的,因为如果您的资产没有编译,您的应用程序将无法工作。

    +3

    是的,我有Cedar堆栈。如果您激活了“实时编译”,则每次存在缓存未命中时都会对其进行编译。其实,如果我停用这个选项('config.assets.compile = true'),那么它根本不起作用。 – alvatar