Bootstrap Glyphicons不能在Rails上运行

时间:2017-04-20 07:00:29

标签: ruby-on-rails glyphicons

在我的Rails 5应用中,我在application.sass文件中有这个...

/*
 *= require bootstrap-sass-official
 ...
 */

 @font-face
   font-family: 'Glyphicons Halflings'
   src: url('/assets/glyphicons-halflings-regular.eot')
   src: url('/assets/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('/assets/glyphicons-halflings-regular.woff') format('woff'), url('/assets/glyphicons-halflings-regular.ttf') format('truetype'), url('/assets/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg')

...根据Ruby on Rails Bootstrap Glyphicons not working中的建议。我在Chrome控制台中收到此错误:Failed to decode downloaded font: http://localhost:3000/assets/glyphicons-halflings-regular.woffetc..表示各种字体格式。

我是否需要将任何内容放入我的Rails资产fonts文件夹中?如果是这样,具体是什么?非常感谢您对此的任何帮助。

1 个答案:

答案 0 :(得分:1)

由于应用程序是Rails 5,更好的方法 - 将字体放在文件夹app/assets/fonts中。

如果您想将它们放在fonts文件夹之外,您需要添加以下配置:

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

然后可以使用网址作为您提到的

@font-face {
    font-family: 'Glyphicons Halflings';
    src: url('/assets/glyphicons-halflings-regular.eot');
    src: url('/assets/glyphicons-halflings-regular.eot?iefix') format('eot'),
         url('/assets/glyphicons-halflings-regular.woff') format('woff'),
         url('/assets/glyphicons-halflings-regular.ttf') format('truetype'),
         url('/assets/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}