font glyphicons not working with bootstrap 3 and rails 4

假装没事ソ 提交于 2019-12-24 14:46:36

问题


I cannot get glyphicons to work with bootstrap 3 and rails. I've scowered the internet and nothing i find helps. In my bootstrap.css file i have:

@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('../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');
}

In application.rb, I have:

config.assets.enabled = true  
config.assets.paths << "#{Rails.root}/app/assets/fonts" 
config.assets.precompile += %w( .svg .eot .woff .ttf )

I have already tried running:

rake assets:precompile RAILS_ENV=development

In application.js I have:

//= require jquery
//= require jquery_ujs
//= require_tree .
//= require bootstrap

In application.css I have:

 *= require_self
 *= require_tree .
 *= require bootstrap
 */

All my fonts are stored in assets/fonts

I've already looked at the following and none of them have worked:

Bootstrap 3+Rails 4 - Certain Glyphicons not working

How to add a custom font to Rails app?

How can I fix this?


回答1:


If you're using bootstrap-sass gem, follow my setup below. If not give it a try, it's the easiest bootstrap setup that I've used.

By the way I'm currently using rails Versions 4.1.6 and 4.1.8

Two gems

gem 'bootstrap-sass'
gem 'autoprefixer-rails'

Your Application.js should look like this below (turbolinks optional)

  /app/assets/javascripts/application.js

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require_tree .

Style sheet should have these two imports

/app/assets/stylesheets/application.scss

@import "bootstrap-sprockets"
@import "bootstrap"

if this setup doesn't work for you try font-path http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

section 2.3.2 css and sass

so your code would go from:

url('/assets/glyphicons-halflings-regular.eot');

to font-path('glyphicons-halflings-regular.eot');




回答2:


Upgrading bootstrap gems, if you use them, fixed it for me:

gem 'sass-rails', '~> 5.0.1' gem 'bootstrap-sass', '~> 3.3.5.1'




回答3:


I'll post my fix.

Because I previously precompiled my assets locally, then added glyphicons after, heroku was not picking up those assets. So I had to re-compile them locally again by doing:

RAILS_ENV=production bundle exec rake assets:precompile

git add public/assets

git commit -m "vendor compiled assets"

And pushing to heroku

git push heroku master

from heroku: https://devcenter.heroku.com/articles/getting-started-with-ruby#introduction



来源:https://stackoverflow.com/questions/27662341/font-glyphicons-not-working-with-bootstrap-3-and-rails-4

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