ruby not load font-awesome

北战南征 提交于 2019-12-04 19:38:19

The easiest way to integrate font-awesome to rails is via font-awesome-rails gem. It will integrate font-awesome to rails asset pipeline.

In your Gemfile add

gem "font-awesome-rails" 

and run bundle install to install the gem

Then in your scss file import it using

@import "font-awesome";

That's it! Now you can use it in your view as

<i class="fa fa-bell-o"></i>

If you prefer to use css instead of scss then add the require statement in your application.css

*= require font-awesome  

Update

If you don't want to use font-awesome-rails gem then follow the steps

  1. Place your fonts in the folder app/assets/fonts

  2. In config/application.rb add the following lines

    # Add fonts path
    config.assets.paths << "#{Rails.root}/app/assets/fonts"
    
    # Precompile additional assets
    config.assets.precompile += %w( .svg .eot .woff .ttf ) 
    
  3. Declare your font in font-awesome.css.erb like

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

I hope this will help you.

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