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

所有在我的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有一些魔法.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...