我正在使用Bootstrap-Sass轨道 这个问题 当我以生产模式运行Rails项目时,我会遇到3x 404错误:

GET http://localhost:3000/assets/twitter/bootstrap/glyphicons-halflings-regular.woff 404 (Not Found) assets/twitter/bootstrap/glyphicons-halflings-regular.woff:1
GET http://localhost:3000/assets/twitter/bootstrap/glyphicons-halflings-regular.ttf 404 (Not Found) assets/twitter/bootstrap/glyphicons-halflings-regular.ttf:1
GET http://localhost:3000/assets/twitter/bootstrap/glyphicons-halflings-regular.svg 404 (Not Found) 

我使用了耙子资产:预编译rails_env =生产以生成静态文件,结果:

I, [2013-11-07T16:52:25.269370 #12948]  INFO -- : Writing myproject/public/assets/application-3517eb39b597107b3dbccbcbf4f0b3cc.js
I, [2013-11-07T16:52:25.315358 #12948]  INFO -- : Writing myproject/public/assets/application-1459bfe79a6477170658d53257e4a8fd.css
I, [2013-11-07T16:52:25.334356 #12948]  INFO -- : Writing myproject/public/assets/twitter/bootstrap/glyphicons-halflings-regular-8b1bdc16b9e098d67afebbf8d59fcea7.eot
I, [2013-11-07T16:52:25.345360 #12948]  INFO -- : Writing myproject/public/assets/twitter/bootstrap/glyphicons-halflings-regular-8d8305e5b6a807076d3ec68e2f190674.svg
I, [2013-11-07T16:52:25.357360 #12948]  INFO -- : Writing myproject/public/assets/twitter/bootstrap/glyphicons-halflings-regular-946071b70245967633bb3a774c60f3a3.ttf
I, [2013-11-07T16:52:25.367360 #12948]  INFO -- : Writing myproject/public/assets/twitter/bootstrap/glyphicons-halflings-regular-d7e2274ad1d940a0b2ce7480810ab223.woff
etc ...

除了这3个字体文件外,所有资产都可以正常工作。我整天搜索,什么都没找到。似乎Rails正在寻找没有这3个文件的没有哈希的版本

我的config/production.rb:

  config.cache_classes = true
  config.eager_load = true
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.serve_static_assets = true
  config.assets.js_compressor = :uglifier
  config.assets.compile = false
  config.assets.digest = true
  config.assets.version = '1.0'
  config.log_level = :info
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify

编辑

我试图覆盖 @font-face变量,但似乎并没有删除旧变量:

@font-face {
  font-family: 'Glyphicons Halflings';
  src: asset-url('twitter/bootstrap/glyphicons-halflings-regular.eot',font);
  src: asset-url('twitter/bootstrap/glyphicons-halflings-regular.eot?#iefix',font) format('embedded-opentype'), asset-url('twitter/bootstrap/glyphicons-halflings-regular.woff',font) format('woff'), asset-url('twitter/bootstrap/glyphicons-halflings-regular.ttf',font) format('truetype'), asset-url('twitter/bootstrap/glyphicons-halflings-regular.svg#glyphicons-halflingsregular',font) format('svg');
}

我现在已经加载了字形,但仍有3x 404个错误。

有帮助吗?

解决方案

那好吧。

我切换了 https://github.com/thomas-mcdonald/bootstrap-sass 。相同的bootstrap版本,没有问题。

编辑更新

Bootstrap-Sass已更新。如果您仍然有404个错误,则需要在GitHub页面上进行一些更改。

其他提示

我有同样的问题。原来我不得不添加 @import "bootstrap-sprockets" 此外 @import "bootstrap" 里面 application.css.sass.

将MIME类型添加到您的Web服务器中。

您必须定义如何提供WOFF文件。

对于IIS,请转到您的IIS并打开矿山窗口

单击添加并键入”沃夫“对于第一个输入框和”应用程序/x-font-woff“对于第二个框

然后重复其他扩展

祝你好运

字体目录不会自动视为资产目录。您需要通过设置明确添加它: config.assets.paths << Rails.root.join("app", "assets", "fonts") 在里面 application.rb 文件。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top