2011-10-04 66 views
8

我無法使Rails 3.1資產管道預編譯工作在生產模式下。它總是失敗的SCSS中引用的圖片有如下錯誤:Ruby on Rails 3.1資產:預編譯和圖像

$ bundle exec rake assets:precompile RAILS_ENV=production 
    rake aborted! 
    rails.png isn't precompiled 
    (in /home/florian/AssetTest/app/assets/stylesheets/application.css.scss) 

但是,當我看在公共/資產目錄,圖像是存在的,所以它是預編譯:

$ ls public/assets | grep rails 
    rails-dd352fc2630e5f9aa5685ef1d7fe5997.png 

的SCSS在這種情況下,文件只是包含了一些測試代碼:

/* 
* This is a manifest file that'll automatically include all the stylesheets available in this directory 
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at 
* the top of the compiled file, but it's generally better to create a new file per style scope. 
*= require_self 
*= require_tree . 
*/ 

body { 
    background: #ffffff image-url('rails.png') no-repeat 0 center; 
} 

如果我不使用SCSS中圖像的URL幫手,只是URL(「/資產/ rails.png」),預編譯工作正常,並manifest.yml文件是g在公共/資產上擁有。有趣的是:如果我將SCSS更改回image-url('rails.png')並運行另一個預編譯,它仍然有效(我猜是因爲圖像現在已經列在清單文件中)。

我在這裏做錯了什麼?我真的不想忽視輔助方法(因爲使用它們是你應該這樣做的方式,對吧?),我絕對不想手動創建清單文件...

回答

5

我已經我自己也會遇到同樣的問題。這顯然是對Rails 3.1.0的一個bug,並且有希望被固定在短期內...

在任何情況下,在production.rb,你可以試試這個:

config.assets.compile = true 

你可能有它設置到false,其中應該是。但是,如果您嘗試使用SCSS中的資產助手,將其設置爲false會導致問題。將該值設置爲true似乎可以在使用這些助手時正確編譯。

查看this issue on github瞭解一些詳細信息。

+1

剛剛更新到Rails 3.1.1rc1建議在github問題,它的工作原理:-) – fwalch

+2

這個答案似乎不好,因爲這個原因:http://stackoverflow.com/questions/8821864/config-assets-compile-真在護欄 - 生產 - 爲什麼 - 不 – Ringo