How to setup assets pipeline in rails 5 to use a custom font?

北慕城南 提交于 2019-12-12 15:25:51

问题


I have to use a custom font Jameel Noori Nastaleeq in a rails 5 app. I have never worked with assets pipeline in rails before. Here are some of the steps I have taken:

  1. create fonts folder in app/assets, and place the extracted ttf font file in it
  2. add config.assets.paths << Rails.root.join("app", "assets", "fonts") in config/application.rb
  3. add the following in app/assets/stylesheets/couplets.scss:

    @font-face {
    font-family: 'Jameel Noori Nastaleeq';
    src:asset-url('JameelNooriNastaleeq.ttf') format("truetype");
    }
    Although there is no error/warnings, the above steps have no effect. Am I missing something.

I have already seen similar questions Custom Font not working in Rails Asset Pipeline Integrating @font-face files into rails asset pipeline but their answers were not helpful.

Complete code in my github repo


回答1:


I had generated the resources using scaffold. Adding desired font-family in app/assets/stylesheets/scaffold.scss fixed the problem. I have updated the github repo.



来源:https://stackoverflow.com/questions/43834753/how-to-setup-assets-pipeline-in-rails-5-to-use-a-custom-font

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!