问题
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
回答1:
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']
来源:https://stackoverflow.com/questions/36884226/fonts-issue-in-productions-envirnment-rails