Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 第三方字体集成Ruby on Rails不工作路径正常,命名良好,在控制台或服务器中编译无错误_Css_Ruby On Rails 4_Fonts - Fatal编程技术网

Css 第三方字体集成Ruby on Rails不工作路径正常,命名良好,在控制台或服务器中编译无错误

Css 第三方字体集成Ruby on Rails不工作路径正常,命名良好,在控制台或服务器中编译无错误,css,ruby-on-rails-4,fonts,Css,Ruby On Rails 4,Fonts,已更新 这就是我的application.scss现在的样子 @font-face { font-family: 'DidotLTStd-Roman'; src: font-url('2C0947_0_0.eot') format("embedded-opentype"); src: font-url('2C0947_0_0.woff') format('woff'); src: font-url('2C0947_0_0.ttf') format("truetype"); f

已更新

这就是我的application.scss现在的样子

@font-face {
  font-family: 'DidotLTStd-Roman';
  src: font-url('2C0947_0_0.eot') format("embedded-opentype");
  src: font-url('2C0947_0_0.woff') format('woff');
  src: font-url('2C0947_0_0.ttf') format("truetype");
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'DidotLTStd-Italic';
  src: font-url('2C0947_1_0.eot') format("embedded-opentype");
  src: font-url('2C0947_1_0.woff') format('woff');
  src: font-url('2C0947_1_0.ttf') format("truetype");
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'AvantGardeGothicITCW02XLt';
  src: font-url('2C0947_2_0.eot') format("embedded-opentype");
  src: font-url('2C0947_2_0.woff') format('woff');
  src: font-url('2C0947_2_0.ttf') format("truetype");
  font-weight: normal;
  font-style: normal;
}


.about {
    font-family: 'AvantGardeGothicITCW02XLt';
}
将此行包括在application.rb中

config.assets.precompile += %w( .svg .eot .woff .ttf )
config.assets.paths << Rails.root.join("app", "assets", "fonts")
但仍然不起作用。chrome控制台没有问题,我仔细检查了文件名


ActionController::RoutingError(没有与[GET]匹配的路由“/assets/webfonts/2C0947_1_0.ttf”):

这是我第一次在RubyonRails应用程序中集成第三方字体。我将按照正确答案中的说明进行操作

它是rails 4.0.2应用程序。 我把我所有的eot、ttf、woff字体都放到app/assets/fonts文件夹中

默认情况下,由于这是一个4.0.2应用程序,它应该查看此字体文件夹

我正在使用scss

我在application.scss文件中添加了以下内容

@font-face {
  font-family: 'DidotLTStd-Roman';
  src:url('2C0947_0_0.woff') format('woff');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'DidotLTStd-Italic';
  src:url('2C09047_1_0.woff') format('woff');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'AvantGardeGothicITCW02XLt';
  src:url('2C09047_2_0.woff') format('woff');
  font-weight: normal;
  font-style: normal;
}

.about {
    font-family: 'DidotLTStd-Italic';
}
我已将
src:font url替换为src:url
我已尝试将此添加到application.rb

config.assets.precompile += %w( .svg .eot .woff .ttf )
config.assets.paths << Rails.root.join("app", "assets", "fonts")
它正在寻找webfonts文件夹,我甚至将fonts文件夹的名称更改为webfonts,但它仍然找不到


因此,我购买的zip文件夹还包含layout.css和mywebfontkit.css,我将它们放入资产中的样式表文件夹中。我还将highlight.js放到了js资产文件夹中

尝试将其添加到您的
应用程序.rb

# Precompile additional assets - from http://stackoverflow.com/questions/10905905/using-fonts-with-rails-asset-pipeline
config.assets.precompile += %w( .svg .eot .woff .ttf )
另外,仅供参考,正是
字体url
版本对我起了作用-如下所示:

@font-face {
  font-family: 'interstate-boldcondensedbold';
  src: font-url("interstate-boldcondensed-webfont.eot");
  src: font-url("interstate-boldcondensed-webfont.eot?#iefix") format("embedded-opentype"), font-url("interstate-boldcondensed-webfont.woff") format("woff"), font-url("interstate-boldcondensed-webfont.ttf") format("truetype"), font-url("interstate-boldcondensed-webfont.svg#interstate-boldcondensedbold") format("svg");
  font-weight: normal;
  font-style: normal;
}

(别忘了以后再重新启动服务器!)

我肯定看到了改进。但是现在我得到了
GEThttp://localhost:3000/fonts/2C09047_1_0.woff 
chrome控制台出现问题。我也切换到了
font-url
。它改进了,因为它现在正在寻找正确的位置,但即使woff文件在那里也找不到它。此外,对
/assets/webfont
的搜索也没有消失。我也尝试了这个版本
config.assets.precompile