Css rails应用程序在heroku上找不到图标

Css rails应用程序在heroku上找不到图标,css,ruby-on-rails,twitter-bootstrap,heroku,Css,Ruby On Rails,Twitter Bootstrap,Heroku,我安装了一个引导主题,一切都在本地运行良好。然而,当我推到heroku时,我的应用程序找不到字体。我预编译了这些资源并推送到heroku,但没有图标 因此,我在development.rb中创建了类似heroku的开发环境: config.assets.debug = true # Disable Rails's static asset server (Apache or nginx will already do this). config.serve_static_asset

我安装了一个引导主题,一切都在本地运行良好。然而,当我推到heroku时,我的应用程序找不到字体。我预编译了这些资源并推送到heroku,但没有图标

因此,我在development.rb中创建了类似heroku的开发环境:

  config.assets.debug = true

  # Disable Rails's static asset server (Apache or nginx will already do this).
  config.serve_static_assets = true

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier
  # config.assets.css_compressor = :sass

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = false

  # Generate digests for assets URLs.
  config.assets.digest = true
现在,我的开发环境找不到字体文件。字体文件位于两个位置:

app/assets/fonts/fontawesome-webfont.*
public/assets/fontawesome-webfont.*
但是,我得到了这个错误:

ActionController::RoutingError (No route matches [GET] "/assets/fontawesome-webfont.svg"):
下面是如何从预编译的css文件(application-xxxxxxxx.css)加载它们:


我做错了什么

保持开发环境不变。我们只需要在生产模式下预编译资产

在此,我希望您需要补充:

应用程序.rb

# Enable the asset pipeline
config.assets.enabled = true
config.assets.paths << "#{Rails.root}/app/assets/fonts" 

然后运行
rakeassets:precompile
并将其推送到
heroku
。祝你一切顺利。

也许你需要补充一下

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


(from)

我尝试使用资产url而不是url,将适当的文件放入资产/字体中,效果很好:

@font-face{
  font-family: 'Font-Awesome';
  src: asset-url('font-awesome.eot');
  src: asset-url('font-awesome.eot?#iefix') format('embedded-opentype'),  
  asset-url('font-awesome.svg') format('svg'),  
  asset-url('font-awesome.woff') format('woff');
  font-weight: normal;
  font-style: normal;
}

对我来说,最简单的修复方法是使用上描述的CDN

删除样式表和字体文件的任何本地副本,并将其放在头部:

<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">

(最新版本自2014年7月7日起生效,请参见上面的链接)

执行以下更改

@font-face{
  font-family:'FontAwesome';
  src:font_url('font/fontawesome-webfont.eot?v=3.0.1');
  src:font_url('font/fontawesome-webfont.eot?#iefix&v=3.0.1') format('embedded-opentype'),
  font_url('font/fontawesome-webfont.woff?v=3.0.1') format('woff'),
  font_url('font/fontawesome-webfont.ttf?v=3.0.1') format('truetype');
  font-weight:normal;
  font-style:normal 
}


它对我有用

我只是清理了我的public/assets文件夹,然后再次预编译了这些资产。推到希罗库和埃特瞧!它很有魅力。有很多重复的文件,资产没有更新。因此,我们必须清理。当上述方法似乎都不适用于我时,我尝试了这种方法

注意:我在, 轨道-4.1.6 Ruby-2.1.3 字体:rails-4.2.0.0


希望它能帮助任何来寻找正确修复方法的人

我在Rails 4.2和Font Aweasome gem“Font Aweasome Rails”中遇到了完全相同的问题

我必须在@font-face声明中使用资产路径(因为我使用的是sass,但我认为资产url也可以使用)

确保编译是为了生产,而不是为了开发或其他环境:

RAILS_ENV=production bundle exec rake assets:precompile
以下是帮助我的资源:


(augustf的评论)

我添加了那行代码并再次预编译..似乎什么都没做。仍然收到相同的错误。您确定我应该指向app/assets文件夹而不是public/assets文件夹吗?嘿,application.rb中的上一行用于在资产路径中包含字体,以便在生产模式下进行预编译。在生产环境中预编译资产时,所有资产都将转到“public/assets”文件夹。您可以使用config.assets.prefix选项更改默认路径。即使如此,如果未正确使用,也请参阅
@font-face{
  font-family:'FontAwesome';
  src:font_url('font/fontawesome-webfont.eot?v=3.0.1');
  src:font_url('font/fontawesome-webfont.eot?#iefix&v=3.0.1') format('embedded-opentype'),
  font_url('font/fontawesome-webfont.woff?v=3.0.1') format('woff'),
  font_url('font/fontawesome-webfont.ttf?v=3.0.1') format('truetype');
  font-weight:normal;
  font-style:normal 
RAILS_ENV=production bundle exec rake assets:precompile