【问题标题】:Bootstrap Glyphicons not working on RailsBootstrap Glyphicons 在 Rails 上不起作用
【发布时间】:2017-09-16 16:00:17
【问题描述】:

在我的 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.woff, etc.. 用于各种字体格式。

我需要将任何东西放入我的 Rails 资产fonts 文件夹吗?如果有,具体是什么?非常感谢您对此提供的任何帮助。

【问题讨论】:

    标签: ruby-on-rails glyphicons


    【解决方案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');
    }
    

    【讨论】:

    • @Matt 很高兴为您提供帮助!非常感谢 - 如果有效,则标记为答案;)
    • 您知道 Rails 4 在处理字形图标方面是否有任何不同?
    • @Matt 我在 rails 4 中知道您没有字体文件夹,但您可以创建它并更新资产管道。修复非常简单。打开位于 config/application.rb 的项目配置文件,并在 Application 类中添加以下行:config.assets.paths << Rails.root.join("app", "assets", "fonts")
    猜你喜欢
    • 1970-01-01
    • 2020-01-07
    • 2013-12-13
    • 2014-06-08
    • 2014-08-05
    • 1970-01-01
    • 2013-11-17
    • 1970-01-01
    • 2013-11-20
    相关资源
    最近更新 更多