简体   繁体   English

Bootstrap 3 Glyphicons未显示在rails生产服务器上

[英]Bootstrap 3 Glyphicons not showing on rails production server

I am unable to load Bootstrap 3 Glyphicons fonts on my live server which are working perfectly on my local server but not on live server. 我无法在我的实时服务器上加载Bootstrap 3 Glyphicons字体,这些字体在我的本地服务器上运行完美但在实时服务器上运行不正常。

I have tried each and everything from SO to everything but it still didnt work for me. 我已经尝试过各种各样的东西,从SO到一切,但它仍然不适合我。

Here is what I am doing: 这是我在做的事情:

applicatin.css.scss applicatin.css.scss

@import "bootstrap-sprockets";
@import 'home';
@import "bootstrap";

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

What I have tried so far: 到目前为止我尝试了什么:

@import "bootstrap-sprockets";
@import 'home';
@import "bootstrap";

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

and

@import "bootstrap-sprockets";
@import 'home';
@import "bootstrap";

@import url("http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css");

and

@import "bootstrap-sprockets";
@import 'home';
@import "bootstrap";

@import url("//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css");

and

@import url("http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css");
@import "bootstrap-sprockets";
@import 'home';
@import "bootstrap";

and

@import url("//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css");
@import "bootstrap-sprockets";
@import 'home';
@import "bootstrap";

but all of them didn't work for me but they are fine on local server. 但他们都不适合我,但他们在本地服务器上很好。

This is the asset pipeline getting in your way... 这是资产管道阻碍你的方式......

Please follow these steps to fix it: 请按照以下步骤进行修复:

  1. Copy font files glyphicons-halflings-regular.* to the folder you-app-path/vendor/assets/fonts 将字体文件glyphicons-halflings-regular。*复制到文件夹you-app-path / vendor / assets / fonts
  2. Copy file boostrap.css to folder you-app-path/vendor/assets/stylesheets 将文件boostrap.css复制到文件夹you-app-path / vendor / assets / stylesheets
  3. Rename copied file boostrap.css to boostrap.css.erb 将复制的文件boostrap.css重命名为boostrap.css.erb
  4. Edit file boostrap.css.erb adjusting the @font-face variable as follows: 编辑文件boostrap.css.erb调整@ font-face变量,如下所示:

     @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.woff2')%>') format('woff2'), 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'); } 

  5. Add/adjust the following line in file you-app-path/config/initializers/assets.rb : 添加/调整文件you-app-path / config / initializers / assets.rb中的以下行:

Rails.application.config.assets.precompile += %w(*.svg *.eot *.woff *.woff2 *.ttf)
  1. add this line to file you-app-path/app/assets/stylesheets/application.css.scss : 将此行添加到文件you-app-path / app / assets / stylesheets / application.css.scss
*= require bootstrap
  1. and finally, restart your rails app and all should work. 最后, 重启你的rails应用程序,所有应该工作。

You can place all you fonts in a folder #{Rails.root}/public/fonts folder and change your code according to the following. 您可以将所有字体放在文件夹#{Rails.root}/public/fonts文件夹中,并根据以下内容更改代码。

@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');
  }

do these changes 做这些改变

@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');
}

And if again not loading any other Glyphicons then change its path ../fonts/ and it will get resolved 如果再次没有加载任何其他Glyphicons然后更改其路径../fonts/它将得到解决

I had the same symptoms that were caused by a CORS issue with my CDN. 我有与我的CDN的CORS问题引起的相同症状。 Was obvious once I finally opened my browser's JavaScript console. 一旦我最终打开浏览器的JavaScript控制台,这一点很明显。

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

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