我在我的Scss文件中配置了一些字体,如下所示:
@font-face {
font-family: 'Icomoon';
src: asset-url('icoMoon.eot?#iefix', font) format('embedded-opentype'),
asset-url('icoMoon.woff', font) format('woff'),
asset-url('icoMoon.ttf', font) format('truetype'),
asset-url('icoMoon.svg#Icomoon', font) format('svg');
}
Run Code Online (Sandbox Code Playgroud)
实际的字体文件存储在/ app/assets/fonts /中
我已经添加config.assets.paths << Rails.root.join("app", "assets", "fonts")到我的application.rb文件中
编译CSS源代码如下:
@font-face {
font-family: 'Icomoon';
src: url(/assets/icoMoon.eot?#iefix) format("embedded-opentype"), url(/assets/icoMoon.woff) format("woff"), url(/assets/icoMoon.ttf) format("truetype"), url(/assets/icoMoon.svg#Icomoon) format("svg");
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行应用程序时,找不到字体文件.日志:
开始获取"/assets/icoMoon.ttf"为127.0.0.1在2012-06-05 23:21:17 +0100服务资产/icoMoon.ttf - 404未找到(13ms)
为什么资产管道没有将字体文件缩小为just/assets?
人们有什么想法?
亲切的问候,尼尔
额外信息:
在检查rails控制台的资产路径和assetprecompile时,我得到以下内容:
1.9.2p320 :001 > y Rails.application.config.assets.precompile
---
- !ruby/object:Proc {}
- !ruby/regexp /(?:\/|\\|\A)application\.(css|js)$/
- .svg
- .eot
- .woff
- .ttf
=> nil
1.9.2p320 :002 > …Run Code Online (Sandbox Code Playgroud) 我有一些我想在我的RoR应用程序中使用的字体,但它们的格式主要是.ttf和.otf等.我如何在Rails应用程序中嵌入这些文件?也就是说,一旦我把它们放在我的资源文件夹中,我将它们嵌入我的CSS和/或LESS文件的语法究竟是什么?
编辑:这是我现在的代码:
@font-face {
font-family: Vow;
src: url('/assets/Vow.otf');
}
h1 {
font-family: Vow;
text-align: center;
}
Run Code Online (Sandbox Code Playgroud)
它似乎对我不起作用.Rails控制台中的输出类似于:
ActionController::RoutingError (No route matches [GET] "/assets/Vow.otf")
Run Code Online (Sandbox Code Playgroud)
用Firebug检查页面说:
downloadable font: download failed (font-family: "Vow" style:normal weight:normal stretch:normal src index:0): status=2147746065
source: http://localhost:3000/assets/Vow.otf
Run Code Online (Sandbox Code Playgroud) 我想在Rails中包含我的自定义字体.
我的文件字体在app/assets/fonts/.
我编辑了CSS:
# in app/assets/stylesheets/application.css
@font-face {
font-family: 'fontello';
src: url('fonts/fontello.eot');
src: url('fonts/fontello.eot#iefix')format('embedded-opentype'),
url('fonts/fontello.woff') format('woff'),
url('fonts/fontello.ttf') format('truetype');
}
Run Code Online (Sandbox Code Playgroud)
我也尝试改变路径url('assets/fonts/fontello.eot'); url('fontello.eot');.
我编辑了配置:
# in config/application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(:default, Rails.env)
module Gui
class Application < Rails::Application
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
end
end
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
我使用Rails 4.0.2.
标题基本概括了所有内容...
我尝试/app/assets/fonts/font.woff从我的css文件添加和引用它,/app/assets/fonts/font.woff但它似乎不起作用.
有任何想法吗?