Bootstrap fonts working with rails 4, asset pipeline
Problems : Cannot load the fonts of bootstrap
Reason : In Rails, all assets are loaded from host:port/assets
not
host:port/fonts
Solution : Replace the source url in @font-face
, from ../fonts/
to
/assets
Original version:
@font-face {
font-family : 'Glyphicons Halflings' ;
src : url('../fonts/glyphicons-halflings-regular.eot') ;
src : url('../fonts/glyphicons-halflings-regular.eot?#iefix') format ( 'embedded-opentype' ), url('../fonts/glyphicons-halflings-regular.woff') format ( 'woff' ), url('../fonts/glyphicons-halflings-regular.ttf') format ( 'truetype' ), url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format ( 'svg' );
}
Edited version:
@font-face {
font-family : 'Glyphicons Halflings' ;
src : url('/assets/glyphicons-halflings-regular.eot') ;
src : url('/assets/glyphicons-halflings-regular.eot?#iefix') format ( 'embedded-opentype' ), url('/assets/glyphicons-halflings-regular.woff') format ( 'woff' ), url('/assets/glyphicons-halflings-regular.ttf') format ( 'truetype' ), url('/assets/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format ( 'svg' );
}