在Ruby on Rails上使用@ font-face?

jos*_*r04 4 css ruby fonts ruby-on-rails

我想在Rails中包含我的自定义字体.

我的文件字体在app/assets/fonts/.

我编辑了CSS:

# in app/assets/stylesheets/application.css

@font-face {
  font-family: 'fontello';
  src: url('fonts/fontello.eot');
  src: url('fonts/fontello.eot#iefix')format('embedded-opentype'),
       url('fonts/fontello.woff') format('woff'),
       url('fonts/fontello.ttf') format('truetype');
}
Run Code Online (Sandbox Code Playgroud)

我也尝试改变路径url('assets/fonts/fontello.eot'); url('fontello.eot');.

我编辑了配置:

# in config/application.rb

require File.expand_path('../boot', __FILE__)
require 'rails/all'

Bundler.require(:default, Rails.env)

module Gui
  class Application < Rails::Application
    config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
  end
end
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

我使用Rails 4.0.2.

Yan*_*ERY 9

您需要使用asset_path在css文件中使用资产(将erb扩展名添加到application.css文件,然后在CSS规则中提供asset_path)

@font-face {
  font-family: 'fontello';
  src: url('<%= asset_path("fontello.eot") %>');
  src: url('<%= asset_path("fontello.eot#iefix") %>') format('embedded-opentype'),
       url('<%= asset_path("fontello.woff") %>') format('woff'),
       url('<%= asset_path("fontello.ttf") %>') format('truetype');
}
Run Code Online (Sandbox Code Playgroud)