1

I am trying to load some additional fonts in my rails application using:

  1. Jruby 1.7.3
  2. Rails 3.2.13

The css (its type is css.scss.erb) document is in app/assets/stylesheets/custom/ folder and looks like follows:

@font-face {
    font-family: 'Lato';
    font-style: normal;
    font-weight: 300;
    src: url('<%= asset_path('/fonts/Lato-Light.woff') %>') format('woff');
}
@font-face {
    font-family: 'Lato';
    font-style: normal;
    font-weight: 400;
    src: url('<%= asset_path('/fonts/Lato-Regular.woff') %>') format('woff');
}
@font-face {
    font-family: 'Lato';
    font-style: normal;
    font-weight: 700;
    src: url('<%= asset_path('/fonts/Lato-Bold.woff') %>') format('woff');
}

The fonts file are in application lib/assets/fonts folder. I have added the following line in my application.rb file:

config.assets.paths << Rails.root.join('lib', 'assets', 'fonts')

I am not getting an request error, so I suppose that my fonts are rendered in the web page but they are not applied. That's the path that the asset_path method generates in the result css file:

enter image description here

Has anyone idea what I am doing wrong?

4

1 回答 1

2

As I have read from Rails 3.1:

The public folder is no longer the supported place for CSS, images and fonts, instead they live in the app/assets/* and vendor/assets/* folders.

So, to set up new fonts, I have followed the steps below:

  1. download the desire font from http://www.google.com/fonts
  2. convert each file - http://www.fontsquirrel.com/tools/webfont-generator
  3. copy all *.eot, *.svg, *.ttf, *.woff files in /vendor/assets/fonts folder
  4. create fonts.css.scss file in the /assets/stylesheets/custom/ folder as follows:
@font-face {

font-family: 'RobotoCondensed';
src: asset-url('robotocondensed-regular-webfont.eot', 'font');
src: asset-url('robotocondensed-regular-webfont.eot?#iefix', 'font') format('embedded-opentype'),
asset-url('robotocondensed-regular-webfont.woff', 'font') format('woff'),
asset-url('robotocondensed-regular-webfont.ttf', 'font') format('truetype'),
asset-url('robotocondensed-regular-webfont.svg#roboto_condensedbold','font') format('svg');
font-weight: normal;
font-style: normal;
}

Source: http://spin.atomicobject.com/2011/09/26/serving-fonts-in-rails-3-1/

于 2013-05-03T07:39:43.867 回答