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

时间:2011-01-05 15:40:56

标签: ruby-on-rails css heroku font-face

我有一些使用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.ru environment.rb 文件以使其与Heroku友好,但是我似乎无法找到它。

提前感谢你们的帮助!

〜丹

3 个答案:

答案 0 :(得分:4)

所以事实证明资源的根被设置为Public/Stylesheets所以我在font-face部分的路径声明是荒谬的。我把简单的东西拿出来并在stylesheets目录下移动了字体,现在一切都很完美!

答案 1 :(得分:2)

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

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

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

答案 2 :(得分:0)

字体目录: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:)