【问题标题】:Glyphicon files not found in rails project在 rails 项目中找不到 Glyphicon 文件
【发布时间】:2018-07-06 13:11:38
【问题描述】:

我在我的项目中使用 glyphicons 作为插件。我不断收到此文件路径的此错误,但什么也没有。但它似乎是确切的文件路径。 我的文件路径不正确吗?

http://localhost:3000/assets/fonts/glyphicons-halflings-regular.ttf 404 (Not Found)



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

https://i.imgur.com/P3EFDaf.png

【问题讨论】:

    标签: javascript css ruby-on-rails


    【解决方案1】:

    由于您的字体在app/assets/fonts 中,您应该能够使用带有文件名的font-url 来引用字体路径 - 不需要相对路径:

    @font-face{
      font-family:'Glyphicons Halflings';
      src:font-url('glyphicons-halflings-regular.eot');
      src:font-url('glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'),
      ...
    }
    

    如果这不能解决问题,您可能需要在 config/application.rb 中的资产路径中显式添加 app/assets/fonts

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

    这是一个很好的资源,详细介绍了使用 Rails 资产管道的 Web 字体:https://gist.github.com/anotheruiguy/7379570

    谢谢!

    【讨论】:

    • 太棒了。谢谢。
    猜你喜欢
    • 2013-06-21
    • 1970-01-01
    • 2013-02-04
    • 1970-01-01
    • 2021-01-19
    • 2020-06-08
    • 2013-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多