如何在Ruby on Rails中使用自定义字体?

时间:2017-06-12 01:30:34

标签: css ruby-on-rails fonts sass webfonts

我有

users.scss
@font-face {
  font-family: scriptina;
  src: asset-url('scriptina.ttf')
}

.script {
  font: scriptina, cursive; 
}

生成

@font-face {
  font-family: scriptina;
  src: url(/scriptina.ttf);
}
/* line 18, C:/Users/Chloe/workspace//app/assets/stylesheets/users.scss */
.script {
  font: scriptina, cursive;
}

http://localhost:3000/scriptina.ttf会生成

  

路由错误
  没有路线匹配[GET]" /scriptina.ttf"

$ ls app/assets
config  images  javascripts  scriptina.ttf  stylesheets

Rails 5

参考:http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

1 个答案:

答案 0 :(得分:1)

一种方法(概述here)将fonts文件夹添加到app/assets,然后通过编辑{{}将其添加到您的应用将查找资源的文件夹中1}}:

config/application.rb

然后将# config/application.rb config.assets.paths << Rails.root.join("app", "assets", "fonts") 移至scriptina.ttf,然后您的app/assets/fonts助手将引用您字体的有效路径。