2011-01-05 68 views
5

我有幾個許可字體,我嵌入到我的Rails應用程序使用CSS @font-face標記。這些字體位於我的Rails 3應用程序的"../Public/Fonts/"路徑中,並可以在任何本地機器上完美呈現,這些機器可以下拉回購併運行。Heroku和@ font-face - 嵌入字體不會顯示在Heroku上

但是,當我將我的應用程序推向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的人,但我似乎無法找到它。

在此先感謝您的所有幫助SO爪牙!

〜丹

+0

您是否檢查過heroku日誌以查看該文件的請求是否觸碰了您的應用服務器? – hornairs 2011-01-05 15:45:58

+0

嘗試添加'使用Rails :: Rack :: Static'到'config.ru' – Zabba 2011-01-05 15:52:43

+0

我會將該行添加到'config.ru'文件還是替換當前的內容? – thoughtpunch 2011-01-05 21:39:47

回答

4

因此,原來資源的根被設置爲Public/Stylesheets,所以我在font-face部分中的路徑聲明是荒謬的。我花了一些時間,在stylesheets目錄下移動字體,現在一切正常。

+0

感謝您的回答。您應該在此標記自己的答案,作爲正確的答案。 – 2011-01-06 05:09:02

0

Fonts目錄: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.1Ruby 2.0.0-p247

它應該工作在她的oku :)