简体   繁体   English

Heroku上的twitter-bootstrap-rails:显示为正方形的Glyphicons

[英]twitter-bootstrap-rails on Heroku: Glyphicons displayed as squares

I have deployed a rails app on Heroku, and I am using the twitter-bootstrap-rails gem to include twitter bootstrap. 我在Heroku上部署了一个rails应用程序,我正在使用twitter-bootstrap-rails gem来包含twitter bootstrap。 Everything works perfectly locally (and in the development environment), but on Heroku (and in production) everything works fine except for the glyphicons, which all display as little squares. 一切都在本地(以及在开发环境中)完美地工作,但是在Heroku(和生产中)一切都很好,除了glyphicons,它们都显示为小方块。

At first I thought this was a problem with the icon sprites not being precompiled, so in my gemfile, I moved the line 'gem twitter-bootstrap-rails' out of the assets group, and I was sure to precompile all my assets before uploading to Heroku. 起初我认为这是一个问题,图标精灵没有被预编译,所以在我的gemfile中,我将“gem twitter-bootstrap-rails”行移出资产组,我确信在上传之前预先编译了我的所有资产到Heroku。

However, this did not solve the problem. 但是,这并没有解决问题。 After inspecting the page, it seems as though the icons are available, but the CSS property that links to them is being overwritten by another CSS rule that sets background-image to none. 检查页面后,似乎图标可用,但链接到它们的CSS属性被另一个将background-image设置为none的CSS规则覆盖。 It seems to be happening in a stylesheet that is part of twitter bootstrap, so I'm not quite sure why this is happening. 它似乎发生在作为twitter bootstrap一部分的样式表中,所以我不太清楚为什么会这样。

Has anyone else had this problem? 有没有其他人有这个问题?

Fixed it. 修复。 The CSS that was causing the problem: 导致问题的CSS:

[class^="icon-"], [class*=" icon-"] {
display: inline;
width: auto;
height: auto;
line-height: inherit;
vertical-align: baseline;
background-image: none;
background-position: 0% 0%;
background-repeat: repeat;

was part of Fontawesome, which is included by default in twitter-bootstrap-rails. 是Fontawesome的一部分,默认包含在twitter-bootstrap-rails中。 The issue was that the Fontawesome icon files were not being precompiled, because they are unusual filetypes. 问题是Fontawesome图标文件没有被预编译,因为它们是不寻常的文件类型。 I went into the production.rb environment file, and added ' .woff', ' .eot', ' .svg', ' .ttf' to the config.assets.precompile list. 我走进production.rb环境文件,并添加“.woff”,“.eot”,“.SVG”,“的.ttf”到config.assets.precompile列表。 I then re-compiled my assets, and the icons showed up! 然后我重新编译了我的资产,图标出现了! Boom. 繁荣。

I solved this problem by adding to config/environments/production.rb : 我通过添加到config/environments/production.rb解决了这个问题:

config.assets.precompile += %w( '.woff', '.eot', '.svg', '.ttf' )

Also I have next string in Gemfile , without github path : 另外我在Gemfile有下一个字符串, 没有github路径

gem 'twitter-bootstrap-rails'

With this configuration Glyphicons displayed well on Heroku. 使用此配置,Glyphicons在Heroku上显示良好。

Make these changes in your bootstrap.css file: 在bootstrap.css文件中进行以下更改:

somewhere around line 1174: 在1174行左右:

-  background-image: url("../img/glyphicons-halflings.png");
+  background-image: image-url("glyphicons-halflings.png");

and somewhere around line 1183: 在1183行附近:

-  background-image: url("../img/glyphicons-halflings-white.png");
+  background-image: image-url("glyphicons-halflings-white.png");

I think that'll do the trick. 我认为这样就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM