1

I have created one file for the fonts in the stylesheets folder in rails application

@font-face {
 font-family: 'MuseoSans500';
 src: url("<%= asset_path('museosans_500-webfont.eot?')%>") format('embedded-opentype');
 font-weight: normal;
 font-style: normal;
 }

@font-face {
 font-family: 'MuseoSans500';
 src: url("<%= asset_path('museosans_500-webfont.woff')%>") format('woff'),
   url("<%= asset_path('museosans_500-webfont.ttf')%>") format('truetype'),
   url("<%= asset_path('museosans_500-webfont.svg#MuseoSans500')%>") format('svg');
font-weight: normal;
font-style: normal;
}

Now When I precompile the assets .. It gives me error on the style.css.erb page. I have kept trace on the sprockets for the path and I got this file. The error is

paths  subpath /home/new_app/app/assets/stylesheets/app-theme/themes/default/style.css.erb
rake aborted!
undefined method `[]' for nil:NilClass

(in /home/hbror/applications/survey/app/assets/stylesheets/application.css)

Arpit Vaishnav
  • 4,739
  • 6
  • 39
  • 57

1 Answers1

1

You should place your fonts in a new asset directory, for example app/assets/fonts and include it in asset directories by placing this in your application.rb:

# Add the fonts path
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')

# Precompile additional assets
config.assets.precompile += %w( .svg .eot .woff .ttf )

Then it should work fine.

R Milushev
  • 4,295
  • 3
  • 27
  • 35
  • I have already Added these paths in the application.rb as per this Answer http://stackoverflow.com/questions/10905905/using-fonts-with-rails-asset-pipeline – Arpit Vaishnav Apr 20 '13 at 07:50
  • Then you have a problem in `styles.css.erb`. Try to prefix it like this: `styles.css.scss.erb` to add sass capabilities. Can we see how your `styles.css.erb` looks like? – R Milushev Apr 20 '13 at 07:59
  • I have change it with styles.css now. And added links on the that with `"<%= asset_path('museosans_500-webfont.ttf')%>"` to `/assets/museosans_500-webfont.ttf` and after that I compile and it works now. – Arpit Vaishnav Apr 20 '13 at 08:00