Ruby on Rails Bootstrap Glyphicons无效

use*_*194 47 ruby-on-rails twitter-bootstrap

我已经在我的网站上添加了bootstrap.这是我正在使用的结构.(我无法删除bootstrap.css文件,因为我根据自己的喜好对其进行了修改).

>app
>>assets
>>>fonts
>>>>4 glypicons icon files.
>>>images
>>>>N/A
>>>javascripts
>>>>Bootstrap.js (Jquery is installed in a gem)
>>>stylesheets
>>>>Bootstrap.css
Run Code Online (Sandbox Code Playgroud)

一切都是正确导入,但问题是glyphicons不工作,我需要它们!

nah*_*nam 100

2015年11月编辑:我会推荐这个gem:https://github.com/twbs/bootstrap-sass它由Bootstrap社区主动维护,并且与Ruby on Rails配合得非常好.

我和你有一个非常相似的问题,但我弄清楚了!在bootstrap.css文件中找到这个部分:

@font-face {
  font-family: 'Glyphicons Halflings';
  src: url('../fonts/glyphicons-halflings-regular.eot');
  src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('../fonts/glyphicons-halflings-regular.woff') format('woff'), url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}
Run Code Online (Sandbox Code Playgroud)

并替换../fonts//assets.这是你的最终代码的样子.

@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');
}
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助!

  • 如果您使用的是未编译的Less或Sass版本,则可以设置`$ icon-font-path:"/ assets /"`变量. (9认同)

vla*_*iov 45

如果您正在使用bootstrap-sass并且遇到此问题,请尝试在您的某个scss文件中导入这样的bootstrap.如果您使用sass,只需转换语法:

@import "bootstrap-sprockets";
@import "bootstrap";
Run Code Online (Sandbox Code Playgroud)

  • 这对我有用.你能解释为什么这是必要的吗? (8认同)
  • @Confusion这里提到它应该被导入以使图标起作用:https://github.com/twbs/bootstrap-sass#-ruby-on-rails (3认同)

Lan*_*tel 36

对于我作为twitter-bootstrap-rails用户:

感谢take的帖子@ GitHub

添加这个:

/* Override Bootstrap 3 font locations */
@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');
}
Run Code Online (Sandbox Code Playgroud)

application.css解决了这个问题.

希望对你有所帮助.


jbm*_*yid 30

我也在努力使boostrap3 glyphicon在rails 4中工作.我通过添加来解决它

@font-face {
  font-family: 'Glyphicons Halflings';
  src: url(asset_path('glyphicons-halflings-regular.eot'));
  src: url(asset_path('glyphicons-halflings-regular.eot?#iefix')) format('embedded-opentype'), url(asset_path('glyphicons-halflings-regular.woff')) format('woff'), url(asset_path('glyphicons-halflings-regular.ttf')) format('truetype'), url(asset_path('glyphicons-halflings-regular.svg#glyphicons_halflingsregular')) format('svg');
}`
Run Code Online (Sandbox Code Playgroud)

application.css.scss文件和

config.assets.paths << "#{Rails}/vendor/assets/fonts"
Run Code Online (Sandbox Code Playgroud)

到application.rb文件.


use*_*149 10

我认为您可能遇到资产管道问题

您想要更改bootstrap.cssbootstrap.css.scss然后替换它使用的位置

@font-face {
  font-family: 'Glyphicons Halflings';
  src: url('../fonts/glyphicons-halflings-regular.eot');
  src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('../fonts/glyphicons-halflings-regular.woff') format('woff'), url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}
Run Code Online (Sandbox Code Playgroud)

font-path(看第2.3.2节- CSS和萨斯)

@font-face {
  font-family: 'Glyphicons Halflings';
  src: font-path('glyphicons-halflings-regular.eot');
  src: font-path('glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'),
    font-path('glyphicons-halflings-regular.woff') format('woff'), 
    font-path('glyphicons-halflings-regular.ttf') format('truetype'), 
    font-path('glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}
Run Code Online (Sandbox Code Playgroud)

也在你的 config/environments/production.rb

# Precompile additional assets
config.assets.precompile += %w( .svg .eot .woff .ttf )
Run Code Online (Sandbox Code Playgroud)

在你的 config/application.rb

# Add the fonts path
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
Run Code Online (Sandbox Code Playgroud)

检查另一个SO帖子是否存在类似问题

希望这可以帮助


Dan*_*nny 5

Bootstrap 3图标看起来像这样:

<i class="glyphicon glyphicon-indent-right"></i>
Run Code Online (Sandbox Code Playgroud)

而Bootstrap 2看起来像这样:

<i class="icon-indent-right"></i>
Run Code Online (Sandbox Code Playgroud)

如果您使用的代码不是最新的(检查b3分支),那么您可能需要分叉并更改自己的图标名称.