LoginSignup
92
84

More than 5 years have passed since last update.

Rails 4 で assets に font を追加する方法

Last updated at Posted at 2014-01-07

app/assets/fonts に ttf, woff, etc... を投入する。終わり。

よくconfig/application.rbに設定を追加しているのを見かけますが間違いです。

config.assets.paths に設定追加の間違い

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

こういうの。
間違いじゃないのですが、app/assets 以下は自動で追加されるので不要です。

config.assets.precompile に対象ファイル追加の間違い

config.assets.precompile << /\.(?:svg|eot|woff|ttf)$/

こういうの。
.css, .js以外は precompile する必要がないので不要です。

以下の設定もよく見かけるのですが、正規表現じゃないのでマッチしません。ということで論外(実は設定していたことは内緒です)。

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

SEE ALSO

まとめ

最初から公式見ておけという結論でした。
無駄にハマってしまって結構疲れて書いているので間違っていたら教えてください。

92
84
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
92
84