@ font-face在rails 4.0中找不到自定义字体的sass url [英] @font-face at rails 4.0 with sass url not found for custom fonts

查看:220
本文介绍了@ font-face在rails 4.0中找不到自定义字体的sass url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在所有我的rails项目中,我试图使用自定义字体,而且还有很多与这个问题有关的答案,我跟着这个答案,这不利于编辑 development.rb 文件

 #添加字体路径
config.assets.paths<< Rails.root.join('app','assets','fonts')

#预编译附加资产
config.assets.precompile + =%w(.svg .eot .woff .ttf)

仍显示没有路由匹配[GET]/ assets / chalkduster-webfont.woff



我设定了 url p>

  @ font-face {
font-family:'chalkdusterregular';
src:url('chalkduster-webfont.eot');
src:url('chalkduster-webfont.svg#chalkdusterregular')format('svg'),
url('chalkduster-webfont.eot?#iefix')format('embedded-opentype') ,'
url('chalkduster-webfont.woff')格式('woff'),
url('chalkduster-webfont.ttf')格式('truetype');
font-weight:normal;
font-style:normal;




更多尝试 font_path(' ')在源代码中也是 font-url()它永远不会工作..:($ / b>

pre> @ font-face {
font-family:'chalkdusterregular';
src:asset-url('chalkduster-webfont.eot');
'src:asset-url('chalkduster-webfont.svg#chalkdusterregular')format('svg'),
asset-url('chalkduster-webfont.eot?#iefix')format('embedded-opentype' ),
asset-url('chalkduster-webfont.woff')格式('woff'),
asset-url('chalkduster-webfont.ttf')格式('truetype');
$ font-weight:normal;
font-style:normal;
}

另外,我只在config / environments / production.rb中添加了字体路径和预编译的附加资源
$ b

 #添加字体路径
c onfig.assets.paths<< Rails.root.join('app','assets','fonts')

#预编译附加资产
config.assets.precompile + = %w(.svg .eot .woff .ttf)

不需要添加到配置/environments/development.rb作为 asset-url 有点神奇。


hi all in my rails project am trying to use custom fonts moreover there are lots of answer related to this question i followed this answer which not helps edited development.rb file

# Add the fonts path
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')

# Precompile additional assets
config.assets.precompile += %w( .svg .eot .woff .ttf )

still it showing No route matches [GET] "/assets/chalkduster-webfont.woff"

and i set me url like

@font-face {
   font-family: 'chalkdusterregular';
    src: url('chalkduster-webfont.eot');
    src:url('chalkduster-webfont.svg#chalkdusterregular') format('svg'), 
    url('chalkduster-webfont.eot?#iefix') format('embedded-opentype'),
         url('chalkduster-webfont.woff') format('woff'),
         url('chalkduster-webfont.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;

}

more over tried font_path('') within source and also font-url() it never works.. :(

解决方案

Try asset-url(). Works for me.

@font-face {
   font-family: 'chalkdusterregular';
    src: asset-url('chalkduster-webfont.eot');
    src: asset-url('chalkduster-webfont.svg#chalkdusterregular') format('svg'), 
         asset-url('chalkduster-webfont.eot?#iefix') format('embedded-opentype'),
         asset-url('chalkduster-webfont.woff') format('woff'),
         asset-url('chalkduster-webfont.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

Also, I only add the fonts path and precompile additional assets in config/environments/production.rb

# Add the fonts path
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')

# Precompile additional assets
config.assets.precompile += %w( .svg .eot .woff .ttf )

Doesn't need to be added to config/environments/development.rb as asset-url works a little magic.

这篇关于@ font-face在rails 4.0中找不到自定义字体的sass url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆