【问题标题】:Loading Bootstrap Glyphicons with Rails 3.2使用 Rails 3.2 加载引导 Glyphicons
【发布时间】:2014-09-13 22:48:32
【问题描述】:

我正在尝试在我的 Rails 应用程序中使用 Bootstrap Glyphicons。我尝试按照以下页面上的说明进行操作:

https://gist.github.com/iamatypeofwalrus/6467148

但是当我运行我的应用程序时,图标没有出现,并且我在控制台中收到以下错误:

Failed to load resource: the server responded with a status of 404 (Not Found) http://0.0.0.0:3000/fonts/glyphicons-halflings-regular.woff
Failed to load resource: the server responded with a status of 404 (Not Found) http://0.0.0.0:3000/fonts/glyphicons-halflings-regular.ttf
Failed to load resource: the server responded with a status of 404 (Not Found) http://0.0.0.0:3000/assets/fonts/glyphicons-halflings-regular.woff
Failed to load resource: the server responded with a status of 404 (Not Found) http://0.0.0.0:3000/assets/fonts/glyphicons-halflings-regular.ttf

有什么想法可能是错的吗?

我的 glyphicon 文件都在 vendor > assets > fonts

我的 bootstrap-glyphicons.css 文件被编辑为具有以下行:

@font-face{font-family:'Glyphicons Halflings';src:url('/assets/glyphicons-halflings-regular.eot');src:url('/assets/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'),url('/assets/glyphicons-halflings-regular.woff') format('woff'),url('/assets/glyphicons-halflings-regular.ttf') format('truetype'),url('/assets/glyphicons-halflings-regular.svg#glyphicons-halflingsregular') format('svg');}.glyphicon{position:relative;top:1px;display:inline-block;font-family:'Glyphicons Halflings';font-style:normal;font-weight:normal;line-height:1;-webkit-font-smoothing:antialiased;}

【问题讨论】:

  • 如何在 Rails 应用程序上安装 Bootstrap?如果 Rails 版本是 4.0 或更高版本,则应使用 bootstrap-sass gem 及其文档。
  • 我使用的是 Rails 3.2。我按照以下说明在没有 gem 的情况下手动安装了 Bootstrap:stackoverflow.com/a/18371521/1720985

标签: ruby-on-rails twitter-bootstrap asset-pipeline glyphicons


【解决方案1】:

我相信您没有正确完成该要点中的第 4 步。您需要更新 CSS 文件中的字体 URL,以便它引用正确的位置。

例子:

src:url('../fonts/glyphicons-halflings-regular.eot');

变成

src:url('/assets/glyphicons-halflings-regular.eot');

根据您的错误消息,我可以看到它仍然引用了错误的位置,即/assets/fonts(正确的路径不应在 URL 中包含fonts

问候,

【讨论】:

  • 感谢您的帮助。我相信我已正确执行了该步骤(我更新了上面的帖子以反映我在 css 文件中的内容)
  • 那么,我相信你的 CSS 中应该有另一个字体定义,它使浏览器从你指定的位置请求不同的文件。你应该仔细检查
猜你喜欢
  • 2012-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-11
  • 2023-04-06
  • 1970-01-01
  • 2015-07-08
  • 1970-01-01
相关资源
最近更新 更多