I'm having trouble using the following @font-face
declaration to work with my Rails 3.1 app. I put the fonts in the Asset Pipeline in its own folder called "Fonts" alongside images
and stylesheets
and javascripts
Here is the declaration I used (generated by Font Squirrel.)
@font-face {
font-family: 'ChunkFiveRegular';
src: url('Chunkfive-webfont.eot');
src: url('Chunkfive-webfont.eot?#iefix') format('embedded-opentype'),
url('Chunkfive-webfont.woff') format('woff'),
url('Chunkfive-webfont.ttf') format('truetype'),
url('Chunkfive-webfont.svg#ChunkFiveRegular') format('svg');
font-weight: normal;
font-style: normal;
}
Anyone successfully utilize @font-face on their Rails 3.1 app?
Update
I just read this thread http://spin.atomicobject.com/2011/09/26/serving-fonts-in-rails-3-1/ that said to change url
to font-url
in the declarations. That didn't seem to work either unfortunately.
I know this is an old question, but I just stumbled across this issue with rails 3.2, and after reading the link to the documentation posted previously, there was no need to edit the application.rb. All I needed to do was do the following in my stylesheet (using sass)
So instead of using url, I used the generic asset-url, which takes 2 arguments, the file and the asset class, in this case 'font'.
Using Rails 4.0 (don't know if this is specific to 4, but anyway), I was only able to make it work with
url(font_path('font-name.ttf'))
. Adding the fonts path to the assets path was not necessary either ().config.assets.paths << "#{Rails.root}/app/assets/fonts"
So, to me this is what worked:
From Rails 3.1 and above you can call
font-url
directly. Like this:Expect your final css to look like that:
Usually works :)
You have to add the folder to the assets path (to file
config/application.rb
), see Rails GuidesAnd you should use the
asset_path
helper:I just updated that article on Atomic Object's Spin blog. Here is the CSS converted (You were looking at the Sass syntax)
While this is late, you could use Compass's
+font-face
mix-in to avoid all this trouble. The mixin helps your life easier byNot remember the awful caveats of the traditional font-face decleration
It internally handles url_helper and format declarations for you
It's far easier to remember
It is declared the following way madams and gentlemen: