1

我在我的rails應用程序中使用typicons和heroku,並且它在本地工作,但不是在生產中,我沒有在heroku中收到任何路由錯誤,我不確定我失蹤了什麼。我在資產文件夾中有一個字體文件夾,我正在使用Typoks字體不顯示在heroku

config.assets.paths << Rails.root.join("app", "assets", "fonts") 

在應用程序類下面的config.application.rb文件中。

的typicons.css.scss(這是在樣式表文件夾中)裏面我有

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

回答

0

我花了幾個小時就同一問題。以下是我工作:在assets/fonts

放置字體文件的typicons.css.scss(這是在樣式表文件夾中)我有內幕:

/* @FONT-FACE loads font into browser */ 
@font-face { 
    font-family: 'typicons'; 
    font-weight: normal; 
    font-style: normal; 
    src: font-url(asset-path('typicons.eot')); 
    src: font-url(asset-path('typicons.eot?#iefix')) format('embedded-opentype'), 
    font-url(asset-path('typicons.woff')) format('woff'), 
    font-url(asset-path('typicons.ttf')) format('truetype'), 
    font-url(asset-path('typicons.svg#typicons')) format('svg'); 
} 

在application.rb中,我說:

config.assets.precompile << /\.(?:svg|eot|woff|ttf)$/ 

最後,我跑了承諾,並推到之前的Heroku以下:

RAILS_ENV=production bundle exec rake assets:precompile 

沒有添加以下行至application.rb中:

config.assets.paths << Rails.root.join("app", "assets", "fonts") 

如果運行在Rails的控制檯Rails.application.class.config.assets.paths,你應該能夠看到是否Rails正在撿資產/字體目錄。在Rails 4.2.5中,字體目錄被自動添加到資產路徑。

希望這節省了一些人的時間。