1

Rails アプリケーションの stylesheets フォルダーにフォント用のファイルを 1 つ作成しました。

@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;
}

アセットをプリコンパイルすると、style.css.erb ページでエラーが発生します。パスのスプロケットを追跡して、このファイルを取得しました。エラーは

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

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

4

1 に答える 1

1

たとえば、フォントを新しいアセット ディレクトリにapp/assets/fonts配置し、これを次のように配置してアセット ディレクトリに含める必要があります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 )

その後、正常に動作するはずです。

于 2013-04-19T18:06:59.483 に答える