asset_path - fonts not applied

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:

Has anyone idea what I am doing wrong?

Answers


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/


Need Your Help

Embeded Youtubu doesn't load on mobile safari, when hidden

javascript ios youtube

Google changed something last days, so I have strange problem with Youtube embeded as iFrame in mobile safari. When iFrame is hidden (some parent div has set display:none) during page load and late...

Login to vbulletin via curl

php curl vbulletin

I am currently trying to figure out how to log into vbulletin from a remote server, the get information from an array of pages that require you to be logged in.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.