Integrating @font-face files into rails asset pipe

2019-01-24 18:31发布

问题:

I'm trying to integrate a designer's html and css files into a rails app. He's got about four @font-face files that are currently linked to in the application.css file. I've stored the fonts in an assets/fonts folder and added that folder to the asset pipeline (in config/application.rb)

I've only ever used Google fonts, where I included the a link to google in the application.html.erb file.

How should I include these font files? Should they (1) stay in the application.css file or (2) be linked to in the application.html.erb file just like javascript and styesheets? For example, something like this:

<%= asset_path('my_webfont.eot') %>

回答1:

Start by putting your fonts into app/assets/fonts. After that, you can include your fonts in a sass / scss file via the font-url('font.eot') helper.

Otherwise, asset_path should still find the fonts there if you're determined to use it.