Bootstrap 3 Glyphicons没有在Heroku上显示

Ton*_*mbe 5 heroku glyphicons ruby-on-rails-4 twitter-bootstrap-3

我在SO上看到了很多关于这个问题的问题和解决方案,但没有一个对我有用.Glyphicons在本地工作很棒,但在桌面浏览器上显示为Heroku上的框.

我正在使用它们:

<span class="glyphicon glyphicon-trash"></span>
Run Code Online (Sandbox Code Playgroud)

这是我的gemfile:

source 'https://rubygems.org'
ruby '2.0.0'

gem 'rails', '4.1.8'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails', '~> 3.1.0'
gem 'turbolinks'
gem 'jquery-turbolinks'
gem 'jbuilder', '~> 2.0.2'
gem 'bootstrap-sass', '~> 3.1.1.0'
gem 'twitter-bootstrap-rails', '~> 3.2.0'
gem 'devise', '~> 3.2.2'
gem 'simple_form'
gem "paperclip", "~> 4.2.0"
gem 'aws-sdk', '~> 1.32.0'
gem 'will_paginate', '3.0.7'
gem 'will_paginate-bootstrap'
gem "friendly_id", "~> 5.0.2"
gem 'faker', '1.2.0'
gem 'auto_html'
gem 'protected_attributes'
gem 'ckeditor', '~> 4.0.11'
gem 'font-awesome-rails'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

group :production do
    gem 'pg'
    gem 'rails_12factor'
end

group :development, :test do    
  gem 'sqlite3'
end
Run Code Online (Sandbox Code Playgroud)

在尝试其他修复后,我目前有production.rb设置如下:

config.serve_static_assets = true
config.assets.compress = true
config.assets.compile = true
config.assets.digest = true
Run Code Online (Sandbox Code Playgroud)

我的application.rb文件包含以下内容:

config.assets.paths << Rails.root.join('app', 'assets', 'fonts')

# Enable the asset pipeline
config.assets.enabled = true

# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'

# Required for Devise on Heroku
config.assets.initialize_on_precompile = false

config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
config.assets.precompile += Ckeditor.assets
config.assets.precompile += %w(ckeditor/*)
config.assets.precompile += %w( .svg .eot .woff .ttf )
config.assets.precompile += [ 'styles.css.scss']
config.assets.precompile += [
    'glyphicons-halflings.png',
    'glyphicons-halflings-white.png'
  ]
Run Code Online (Sandbox Code Playgroud)

我也试过跑步

bundle exec rake assets:precompile
Run Code Online (Sandbox Code Playgroud)

bundle exec rake assets:precompile RAILS_ENV=production
Run Code Online (Sandbox Code Playgroud)

我已经尝试了很多修复,我现在设置的东西可能是错的.一切都在当地很有效.我还有一个问题,即text-align:center没有从我的CSS文件推送到heroku.我会将其作为一个单独的问题发布,但我提到它以防它是资产管道的相关问题.

这是我在应用程序中加载样式表的方法:

 <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
Run Code Online (Sandbox Code Playgroud)

这些是我的样式表:

application.css.scss
pages.css.scss
posts.css.scss
scaffolds.css.scss
styles.css.scss
users.css.scss
Run Code Online (Sandbox Code Playgroud)

在我的application.css.scss中:

*= require_self
*= require_tree .
*= require font-awesome
Run Code Online (Sandbox Code Playgroud)

在我的styles.css.scss中

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


@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)

以下是Chrome的错误:

来自" http://thetens.herokuapp.com "的字体已被跨源资源共享策略阻止加载:请求的资源上不存在"Access-Control-Allow-Origin"标头.原因' http://www.thetens.us '因此不允许访问.响应的HTTP状态代码为404. jquery-91eecca5c0fff73b540ae82e1b1833c8.js:3581 GET http://thetens.herokuapp.com/fonts/glyphicons-halflings-regular.woff jquery-91eecca5c0fff73b540ae82e1b1833c8.js:3581(匿名函数)jquery-91eecca5c0fff73b540ae82e1b1833c8. js:3120 firejquery-91eecca5c0fff73b540ae82e1b1833c8.js:3232 self.fireWithjquery-91eecca5c0fff73b540ae82e1b1833c8.js:3444 jQuery.extend.readyjquery-91eecca5c0fff73b540ae82e1b1833c8.js:3475 completed(index):1来自origin的字体'已禁止通过跨源资源共享策略加载http://thetens.herokuapp.com ':请求的资源上没有"Access-Control-Allow-Origin"标头.原因' http://www.thetens.us '因此不允许访问.响应的HTTP状态代码为404.(索引):1 GET http://thetens.herokuapp.com/fonts/glyphicons-halflings-regular.ttf

更新:我评论了

# config.action_controller.asset_host = "http://thetens.herokuapp.com"
Run Code Online (Sandbox Code Playgroud)

现在我只得到两个错误:

GET http://www.thetens.us/fonts/glyphicons-halflings-regular.woff jQuery的6156cfcaa88efb694ac4f​​ac3d8cef9c4.js:3581(匿名函数)jQuery的6156cfcaa88efb694ac4f​​ac3d8cef9c4.js:3120 firejquery-6156cfcaa88efb694ac4f​​ac3d8cef9c4.js:3232 self.fireWithjquery-6156cfcaa88efb694ac4f​​ac3d8cef9c4 .js:3444 jQuery.extend.readyjquery-6156cfcaa88efb694ac4f​​ac3d8cef9c4.js:3475完成(索引):1 GET http://www.thetens.us/fonts/glyphicons-halflings-regular.ttf

MZa*_*oza 0

您必须绝对链接到字体,例如

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


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

标记确保字体在 heroku 中正确链接