【问题标题】:Bootstrap glyphicons error 404 in production生产中的引导字形图标错误 404
【发布时间】:2013-11-19 08:52:42
【问题描述】:

我正在使用 bootstrap-sass-rails this issue,当我在生产模式下运行我的 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) 

我使用 rake assets:precompile RAILS_ENV=production 来生成带有结果的静态文件:

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 个文件哈希的版本,但 rake 使用哈希生成它们

我的配置/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 错误。

【问题讨论】:

    标签: ruby-on-rails twitter-bootstrap-3 bootstrap-sass


    【解决方案1】:

    那好吧。

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

    编辑更新

    bootstrap-sass 已更新。如果仍然出现 404 错误,则需要按照 github 页面上的说明进行一些更改。

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题。原来我必须在application.css.sass里面加上@import "bootstrap"之外的@import "bootstrap-sprockets"

      【讨论】:

      • 是的,如更改日志中所述,如果您不是第一次安装它,请再次查看 README 页面!
      【解决方案3】:

      将 MIME TYPE 添加到您的网络服务器中。

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

      对于 IIS,转到您的 IIS 并打开 MINE 类型窗口

      点击添加并为第一个输入框输入“woff” 和第二个框的“application/x-font-woff

      然后重复其他扩展

      祝你好运

      【讨论】:

      • Google 把我带到了这里,被否决的 IIS 答案对我有用,谢谢,没有使用 Ruby,但解决方案是有效的
      【解决方案4】:

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

      【讨论】:

      • 我没有字体目录。 bootstrap-sass-rails 已经包含字体,它们不在我的项目中。或者我没听懂你在说什么。
      猜你喜欢
      • 1970-01-01
      • 2014-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-22
      • 2018-08-08
      • 1970-01-01
      • 2021-07-04
      相关资源
      最近更新 更多