Font awesome Rails won't work after deploying. It looks like bad Unicode characters. Why?

夙愿已清 提交于 2019-12-07 22:43:06

问题


In my local machine fontawesome is working perfectly (Im using 4.1 gem). But when uploaded to Heroku it stops working. I looks like bad unicode characters. I have included the following line in config and precompiled assets but it didn't work :

config.assets.paths << Rails.root.join(‘app’, ‘assets’, ‘fonts’)
config.assets.precompile += %w( .svg .eot .woff .ttf )

Please look at this image :

On the left is the problem. On the right is the correct version. What might be the problem? Here's the link to the Heroku app : http://fast-garden-6871.herokuapp.com/

Update It looks like /assets/fontawesome-webfont.eot is missing in the production machine!


回答1:


In your css file, change url to asset-url under @font-face.

Also did you precompile assets after deployment?

RAILS_ENV=production rake assets:precompile



回答2:


Finally fixed it! In custom.css I added the following lines:

@font-face {
  font-family: 'FontAwesome';
  src: asset-url('fontawesome-webfont.eot');
  src: asset-url('fontawesome-webfont.eot?#iefix') format('embedded-opentype'), asset-url('fontawesome-webfont.woff') format('woff'), asset-url('fontawesome-webfont.ttf') format('truetype'), asset-url('fontawesome-webfont.svg#fontawesomeregular') format('svg');
  font-weight: normal;
  font-style: normal;
}

The problem was, rails will generate the font file with a hash like it generate css files. But the css is not updated with this new generated file. So the system can't find the font. With the above code, the system will assign the right url!



来源:https://stackoverflow.com/questions/24044660/font-awesome-rails-wont-work-after-deploying-it-looks-like-bad-unicode-charact

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