加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – @ font-face在rails 4.0与sass url找不到自定

发布时间:2020-12-16 20:35:25 所属栏目:百科 来源:网络整理
导读:所有在我的rails项目我试图使用自定义字体,而且有很多答案与这个问题相关,我遵循这个答案,这不帮助编辑的development.rb文件 # Add the fonts pathconfig.assets.paths Rails.root.join('app','assets','fonts')# Precompile additional assetsconfig.assets
所有在我的rails项目我试图使用自定义字体,而且有很多答案与这个问题相关,我遵循这个答案,这不帮助编辑的development.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 )

仍然显示没有路线匹配[GET]“/assets/chalkduster-webfont.woff”

我把我的URL设置为

@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;

}

更多的是在源代码中再次使用font_path(”),而font-url()也不会工作.

解决方法

尝试asset-url().为我工作
@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;
}

此外,我只在config / environments / production.rb中添加字体路径并预编译其他资源

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

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

不需要添加到config / environments / development.rb,因为asset-url有一些魔法.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读