2011-09-03 129 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