字体问题在生产环境轨道 [英] fonts issue in productions envirnment rails
问题描述
我制作了一个在开发环境中工作良好的rails(4.2.4)应用程序,但是当我将其部署到数字海洋时,它不会获取字体,并且会出现像
无法加载资源:服务器的状态为404(未找到)
,路径如
http://Server-IP/assets/raleway-bold.woff2
我尝试了很多组合来提供路径,但都是徒劳的,除了一个,生产。
我对资产的结构有一点点不同
$ p $ lt; code> assets
- 字体
- javascripts
- 样式表
- admin
- web
- application.js
- fonts.cs
- application.cs
和fonts.cs我提供的路径类似于
@ font-face {
fo nt-family:'dpdidot_htfm96medium';
src:url('/ assets / dp_didot-htf-m96-medium-webfont.eot'); ('/ assets / dp_didot-htf-m96-medium-webfont.eot?#iefix')格式('woff'),$ b $ url('/ assets / dp_didot-htf-m96-medium-webfont.woff')格式('woff'),$ b $ ('/ assets / dp_didot-htf-m96-medium-webfont.ttf')格式('truetype'),
url('/ assets / dp_didot-htf-m96-medium-webfont.svg#dpdidot_htfm96medium ')格式('svg');
font-weight:normal;
font-style:normal;
$ b $ / code $ / pre
$ b $ p 解决方案明白了。使用Rails的默认预编译资产只会生成 application.js
和 application.css
。如果您想要预编译生成像字体一样的解压缩资源,请将其添加到 Rails.application.config.assets.precompile
中。您可以将它添加到 assets.rb
Rails.application.config .assets.precompile + = ['* .js','* .css','* .woff2','* .woff']
I made an rails (4.2.4) app which work fine in development environment but when I deployed it on digital ocean it doesn't get fonts, with an error like
Failed to load resource: the server responded with a status of 404 (Not Found)
with path like
http://Server-IP/assets/raleway-bold.woff2
I tried many combinations to provide path but all in vain except one, which works in development but not in production.
I have little different structure for assets
assets
- fonts
- javascripts
- stylesheets
- admin
- web
- application.js
- fonts.cs
- application.cs
and in fonts.cs I am providing path like
@font-face {
font-family: 'dpdidot_htfm96medium';
src: url('/assets/dp_didot-htf-m96-medium-webfont.eot');
src: url('/assets/dp_didot-htf-m96-medium-webfont.eot?#iefix') format('embedded-opentype'),
url('/assets/dp_didot-htf-m96-medium-webfont.woff2') format('woff2'),
url('/assets/dp_didot-htf-m96-medium-webfont.woff') format('woff'),
url('/assets/dp_didot-htf-m96-medium-webfont.ttf') format('truetype'),
url('/assets/dp_didot-htf-m96-medium-webfont.svg#dpdidot_htfm96medium') format('svg');
font-weight: normal;
font-style: normal;
}
Whats wrong with it
解决方案 Got it. The default precompiling assets with Rails will only generate application.js
and application.css
. If you want the precompile generate unpacked assets like the fonts, add it to the Rails.application.config.assets.precompile
this is the example. You can add this to assets.rb
Rails.application.config.assets.precompile += ['*.js', '*.css', '*.woff2', '*.woff']
这篇关于字体问题在生产环境轨道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!