2014-02-11 99 views
1

使用Rails 4自定義字體不能在heroku中工作

我讀過很多關於如何讓我的自定義字體在heroku中工作的線程。他們以開發模式在本地工作,但是當推到heroku時,他們沒有出現。

我@字體面位於主樣式表

@font-face { 
    font-family: 'caviar_dreamsregular'; 
    src: font-url('caviardreams-webfont.eot'); 
    src: font-url('caviardreams-webfont.eot?#iefix') format('embedded-opentype'), 
     font-url('caviardreams-webfont.woff') format('woff'), 
     font-url('caviardreams-webfont.ttf') format('truetype'), 
     font-url('caviardreams-webfont.svg#caviar_dreamsregular') format('svg'); 
    font-weight: normal; 
    font-style: normal; 

} 

application.rb中

config.assets.paths << "#{Rails.root}/app/assets/fonts" 

我已經預編譯資產

rake assets:precompile 

在Heroku的日誌中沒有錯誤。

無法理解這一點,有沒有人有任何建議?

UPDATE:

訪問我的手機上的網站和字體的作品...清除緩存的計算機上,仍不能正常工作的計算機上。

回答

6

這可能歸結爲幾個問題;最值得注意的是,我會建議你不使用動態資產路徑:


指紋

Rails使用asset fingerprinting當您預編譯的資產

這樣做的原因是爲了讓每個資產被單獨分配給系統,從而提供更強大的結構(或某物)。基本上,它增加了一個MD5哈希您的資產文件名末尾:

global-908e25f4bf641868d8683022a5b62f54.css 

路徑

由於動態指紋使所有預編譯的資產有不同的名稱,你需要使用Rails的動態路徑助手:

#app/assets/stylesheets/application.css.scss 
@font-face { 
    font-family: 'caviar_dreamsregular'; 
    src: asset-url('caviardreams-webfont.eot'); 
    src: asset-url('caviardreams-webfont.eot?#iefix') format('embedded-opentype'), 
     asset-url('caviardreams-webfont.woff') format('woff'), 
     asset-url('caviardreams-webfont.ttf') format('truetype'), 
     asset-url('caviardreams-webfont.svg#caviar_dreamsregular') format('svg'); 
    font-weight: normal; 
    font-style: normal; 
} 

您需要使用動態樣式表引擎,如SASS來處理dy namic路徑

+1

這工作大聲笑。 – Seal

+1

我的問題是我有供應商/資產/字體中的字體(甚至添加了'config.assets.paths << Rails.root.join('vendor','assets','fonts')'我無法讓它工作)。一旦我將字體移動到應用程序/資產/字體並重新部署,他們開始使用Heroku! – Nick