1

Whole day I am trying to set up to work @font-face on localhost. Here's my setup:

application.rb and development.rb:

config.assets.paths << "#{Rails.root}/app/assets/fonts"

In CSS:

@font-face {
  font-family: 'my_font';
  src: asset-url('font_name.eot', font);
  src: asset-url('font_name.eot?#iefix', font) format('embedded-opentype'),
       asset-url('font_name.woff', font) format('woff'),
       asset-url('font_name.ttf', font)  format('truetype'),
       asset-url('font_name.svg#AndrogyneMedium', font) format('svg');    
}

I've tried also to precompile assets:

bundle exec rake assets:precompile

I've tried also couple times to restart app, but nothing didn't help me.

Could anyone give me any advice, how to fix it? Thank you in advance.

EDIT: Ok guys, I'll give you zillion dollars who help me to solve it :) I've tried probably everything...

1
  • This sounds stupid, but have you checked to see if the font urls are resolving? Commented Dec 25, 2012 at 22:22

3 Answers 3

1

You need to add the files to the precompile config as well:

config.assets.precompile += %w(*.svg *.eot *.ttf *.woff)
Sign up to request clarification or add additional context in comments.

Comments

1

I struggled on this issue to so my solution was to see if typekit had the font that I was looking for in which they did and I kept it moving. You should not spend hours worrying about fonts but rather the code so check it out because it will save you the time and headache.

Comments

0

If you organize your fonts in assets/fonts you can use the following setup.

# config/application.rb
# Serve fonts via Asset Pipeline
config.assets.paths << Rails.root.join("app", "assets", "fonts")
config.assets.precompile += %w( .svg .eot .woff .ttf )

I'm using the font-awesome icon font, so in the font-awesome.sass I use a font-url helper (that differs from your asset-url).

# vendor/stylesheets/font-awesome.sass
@import compass/css3/font-face

@font-face
  font-family: 'FontAwesome'
  src: font-url("fonts/fontawesome-webfont.eot")
  src: font-url("fonts/fontawesome-webfont.eot?#iefix") format("eot"), font-url("fonts/fontawesome-webfont.woff") format("woff"), font-url("fonts/fontawesome-webfont.ttf") format("truetype"), font-url("fonts/fontawesome-webfont.svg#FontAwesome") format("svg")

Source: related stackoverflow question

2 Comments

I don't know what am I doing wrong, but I have exactly this setup and it still doesn't work... still those new fonts don't work.
Hi Thomas... trying & trying, but unfortunately, the same... the fonts are not loaded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.