Skip to content

Instantly share code, notes, and snippets.

@leommoore
Last active October 13, 2017 03:30
Show Gist options
  • Save leommoore/2251151 to your computer and use it in GitHub Desktop.
Save leommoore/2251151 to your computer and use it in GitHub Desktop.
Using Font-Awesome with Rails 3.1 using CSS

#Using Font-Awesome with Rails 3.1 using CSS

  1. Download font-awesome from https://github.com/FortAwesome/Font-Awesome

  2. Put the font folder in the app/assets. I renamed the folder from font to fonts to make it clearer

  3. Add config.assets.paths << "#{Rails.root}/app/assets/fonts" to config/application.rb. This is to include the apps/assets/fonts folder in the asset pipeline

  4. Put the font-awesome.css file in the app/assets/stylesheets folder

  5. The first part of the css should be:

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

You should then be able to use:

<div style="font-size: 24px;">
    <i class="icon-camera-retro"></i> icon-camera-retro
</div>
@DanCoughlin
Copy link

Thank you for this! I was screwing up the paths to the fonts in the font-awesome.css and this saved me.

@denisinla
Copy link

Awesome ! Thanks for this Gist !

@moflo
Copy link

moflo commented Nov 5, 2012

With Rails 3.2 we needed to explicitly include the "/asset/font-awesome..." in the CSS file like so:

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

Copy link

ghost commented May 4, 2013

Great gist! I just took the stock style sheet and removed "../font/" from the urls. Don't for get to restart your server if the font isn't loading.

@KrissieCope
Copy link

You guys rock. Perfect solution to my problem!

@joeldom
Copy link

joeldom commented Aug 29, 2013

Hey I'm using Mou on Mac, and it opens with a nice kitchen sink markdown template that shows how to use font-awesome. Trouble is closing Mou I can't find where to refer to how to use icons and font-awesome. ANy help would be crazy awesome.

@marcomu
Copy link

marcomu commented Jun 11, 2014

Thank you! in Rails 4 also you have to explicitly include the "/asset/font-awesome..." in the CSS file! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment