Heroku和@ font-face – 嵌入式字体不会在Heroku上显示

我使用CSS @font-face标签将一些许可字体嵌入到我的Rails应用程序中。 这些字体位于我的Rails 3应用程序中的"../Public/Fonts/"路径中,并在我下拉回购并运行的任何本地计算机上完美呈现。

但是,当我将我的应用程序推送到Heroku时,它似乎无法找到字体。 你可以告诉它它正在查看字体目录,但永远不能访问它们。 我在哪里放置字体或者如何在@ font-face声明中键入字体路径似乎并不重要。

我的字体位于#{RAILS.root}/public/fonts/ChunkFive

这是我的@ font-face声明:

 @font-face { font-family: "ChunkFive"; src: url("../fonts/ChunkFive/ChunkFive-webfont.eot"); src: local("?"), url("../fonts/ChunkFive/ChunkFive-webfont.woff") format("woff"), url("../fonts/ChunkFive/ChunkFive-webfont.ttf") format("truetype"), url("../fonts/ChunkFive/ChunkFive-webfont.svg") format("svg"); } 

这是我为每种字体获得的404资源未找到消息:

 Request URL:http://thedanbarrett.heroku.com/fonts/ChunkFive/ChunkFive-webfont.woff Request Method:GET Status Code:404 Not Found Request Headers Referer:http://thedanbarrett.heroku.com/home User-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML,like Gecko) Chrome/8.0.552.224 Safari/534.10 Response Headers Age:0 Connection:keep-alive Content-Length:727 Content-Type:text/html Date:Wed, 05 Jan 2011 15:25:21 GMT Server:nginx/0.7.67 Via:1.1 varnish X-Runtime:0.001344 X-Varnish:764492621 

奇怪的是,它在同一根文件夹中查找并加载样式表,图标和图像。 只是重申字体嵌入和工作从本地服务器完美运行,即使在没有安装字体的主机上也是如此。

我确实在网上找到一个有类似问题的人参考,他们改变了他们的config.ruenvironment.rb文件,使其与Heroku友好,但我似乎无法找到它。

在此先感谢你们的帮助!

〜丹

所以事实certificate资源的根设置为Public/Stylesheets所以我在font-face部分的路径声明是荒谬的。 我把容易拿出来并将样式移到了样式表目录下,现在一切正常!

以下是Heroku的一个示例: http : //www.arailsdemo.com/posts/12

以下是相应的样式表http://www.arailsdemo.com/stylesheets/application.css

我不记得需要任何配置更改。 希望它有所帮助。

字体目录: app/assets/fonts/

将以下行添加到production.rb

 config.serve_static_assets = true 

在styles.css.scss中

 @font-face { font-family: "mycustomfont"; src:url(asset_path("mycustomfont.eot")); src:url(asset_path("mycustomfont.eot?#iefix")) format("embedded-opentype"), url(asset_path("mycustomfont.ttf")) format("truetype"), url(asset_path("mycustomfont.svg#mycustomfont")) format("svg"), url(asset_path("mycustomfont.woff")) format("woff"); font-weight: normal; font-style: normal; } 

环境: Rails 4.0.1 Ruby 2.0.0-p247

它应该适用于heroku 🙂