我想将自定义字体集成到我的Ruby on Rails应用程序中。我的文字是西里利语的。我已经从谷歌字体下载了一种特殊的西里克字体。在遵循一些教程后,我仍然会遇到同样的问题:应用程序工作(localhost 加载没有错误(,但书写中的字体没有改变。
这是我的文件夹的样子:
-app
--assets
---fonts
----Oswald-Regular.ttf
---stylesheets
----application.css
----styles.scss
这是我的config/application.rb的样子:
require_relative 'boot'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Signup
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.2
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading
# the framework and any gems in your application.
end
end
这是我的应用程序.css看起来像:
h1{
font-family:"Oswald";
}
这是我的styles.scss的样子:
@font-face {
font-family: "Oswald";
src: url("assets/fonts/Oswald-Regular.ttf") format("truetype");
}
虽然没有错误消息,但我仍然不明白我可以添加什么来让我的应用程序正常工作......
@font面写为
@font-face {
font-family: "Oswald";
src: url(<%= asset_path 'fonts/Oswald-Regular.ttf' %>) format("truetype");
}
将文件名application.css
更改为application.css.erb