我在试着加载图标。在开发中,它是有效的,因为我不需要预编译任何东西。但在生产中它不装载。浏览器控制台说:
"NetworkError: 404 Not Found - http://production.site.com/assets/glyphicons-halflings-regular.ttf"下面是我的glyphicons.scss文件的行:
@font-face{font-family:'Glyphicons Halflings';src:url(asset_path('/assets/glyphicons-halflings-regular.eot'));src:url(asset_path('/assets/glyphicons-halflings-regular.eot?#iefix')) format('embedded-opentype'),url(asset_path('/assets/glyphicons-halflings-regular.woff')) format('woff'),url(asset_path('/assets/glyphicons-halflings-regular.ttf')) format('truetype'),url(asset_path('/assets/glyphicons-halflings-regular.svg#glyphicons-halflingsregular')) format('svg');}.glyphicon{position:relative;top:1px;display:inline-block;font-family:'Glyphicons Halflings';font-style:normal;font-weight:normal;line-height:1;-webkit-font-smoothing:antialiased;}我的字体文件夹在app/assets中:
app/
assets/
├── fonts
│ ├── glyphicons-halflings-regular.eot
│ ├── glyphicons-halflings-regular.svg
│ ├── glyphicons-halflings-regular.ttf
│ └── glyphicons-halflings-regular.woff在我的application.rb文件中,我有以下内容:
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
config.assets.precompile += %w( *.svg *.eot *.woff *.ttf )这不是我唯一要做的吗?我不知道Rails在哪里找字体?我怎么才能解决这个问题?
==UPDATE==来自曼迪普的建议:
application.rb文件:
# config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
config.assets.precompile += %w( *.svg *.eot *.woff *.ttf )glyphicons.scss
@font-face{font-family:'Glyphicons Halflings';src:font-url('/assets/glyphicons-halflings-regular.eot');src:font-url('/assets/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'),font-url('/assets/glyphicons-halflings-regular.woff') format('woff'),font-url('/assets/glyphicons-halflings-regular.ttf') format('truetype'),font-url('/assets/glyphicons-halflings-regular.svg#glyphicons-halflingsregular') format('svg');}.glyphicon{position:relative;top:1px;display:inline-block;font-family:'Glyphicons Halflings';font-style:normal;font-weight:normal;line-height:1;-webkit-font-smoothing:antialiased;}我推了我的代码并重新部署,但它仍然不起作用
发布于 2014-09-17 15:26:01
,因为您使用的是rails >4,所以您不需要在资产中添加字体文件夹,因为默认情况下它是添加在资产中的。也使用sass,这样您就可以使用font-url helper了。如果你看看docs,它会说:
当使用资产管道时,必须重写资产路径,sass-rails为以下资产类提供-url和-path帮助(在Sass中使用连字符,在Ruby中强调):图像、字体、视频、音频、JavaScript和样式表。
所以你可以这样使用它:
src: font-url('glyphicons-halflings-regular.eot');https://stackoverflow.com/questions/25894333
复制相似问题