fonts issue in productions envirnment rails

做~自己de王妃 提交于 2020-01-06 13:28:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!