0

In CSS:

@font-face {
  font-family: 'some_name';
  src: url('font_name.eot');
}

In application.rb:

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

On Heroku this setup works well, but on localhost doesn't. Am I missing something for correct displaying non-standard fonts on localhost? I am running on Mountain Lion.

Thanks

2 Answers 2

1

The scr path specification of the font is relative.

In production environment, all assets are compiled and assets of different types are placed in one folder, accessible at /assets/asset-name. Which means both font and css file will be in same folder, and relative path would do. In development environment, however, assets ain't compiled and ain't combined together, meaning they're accessed at /assets/ASSET-TYPE/asset-name. So the font won't be in the same folder as the stylesheet will, and relative path won't help to find the actual font file.

Rails has an asset-url CSS helper, which works in both envs, it'll be replaced during compilation to the url(path-to-asset).

@font-face {
  font-family: 'The Font';
  src: asset-url('the_font.eof', font);
}
Sign up to request clarification or add additional context in comments.

Comments

1

This solution works for me:

@font-face {
  font-family: 'some_name';
  src: url('/assets/font_name.eot');
}

Comments

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.