2012-02-01 24 views
5

在我的rails(2.x)應用程序中。我想在我的視圖中使用自定義字體。所以我在字體文件夾下公開添加了字體文件。當我嘗試通過URL或通過應用程序獲取字體時,它通過路由錯誤。我猜rails路徑無法識別格式/文件。糾正我,如果我錯了,給我的解決方案如何使Rails路徑響應字體文件(eot)?

CSS代碼:

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

} 

注:我也可以通過直接輸入路徑獲得WOFF,TTF文件,但不EOT文件。

Error trace: 
Unknown action 
No action responded to fonts. Actions: XXXXXXsomeactionsXXXXX and rescue_404 

在此先感謝, 阿倫。

回答

4

我通過移動public/stylesheets/fonts下的字體文件夾解決了上述問題。並做出如下代碼。

font-face { 
    font-family: 'Effra'; 
    src: url('fonts/effra_std_rg-webfont.eot'); 
    src: url('fonts/effra_std_rg-webfont.eot?#iefix') format('embedded-opentype'), 
     url('fonts/effra_std_rg-webfont.woff') format('woff'), 
     url('fonts/effra_std_rg-webfont.ttf') format('truetype'), 
     url('fonts/effra_std_rg-webfont.svg#EffraRegular') format('svg'); 
    font-weight: normal; 
    font-style: normal; 
} 

希望這會對其他人有所幫助。

+0

我遇到了類似的問題:本地沒有通過資產管道提供字體(嘗試字體路徑時結果爲404)。以上是一種解決方法,但我很想知道實際的修復方法。 – Geoff 2013-03-26 20:48:34

相關問題