2013-05-04 78 views
1

我想了解有關webapps的信息。我決定通過這樣做來學習,並選擇以(i)開始露營。它是小的&(ii)。我知道一些紅寶石。Favicon未顯示野營

圖標沒有顯示。我使用的是從其他網站取得的圖標,因此它知道它的文件格式是有效的。

這裏是控制器的代碼。

class Favicon < R '/favicon\.ico' 
    # Load the favicon into memory 
    FAVICON = File.read('favicon.ico') 
    def get 
     @headers['Content-Type'] = "image/x-icon" 
     FAVICON 
    end 
    end 

這裏是從視圖的代碼: 我特意放置鏈接到圖標兩倍的實驗。沒有快樂。

def layout 

html do 
    head do 
    title 'Custom Made Kameez' 
    link :rel => 'icon', :href => 'favicon.ico', :type => 'image/x-icon' 
    link :rel => 'shortcut icon', :href => 'favicon.ico', :type => 'image/x-icon' 
    link :rel => 'stylesheet', :type => 'text/css', :href => '/styles.css', :media => 'screen'   
    end 

我已經嘗試清除我的緩存,並使用Firefox和IE,同樣的問題。

回答

0

據我所見,有兩個問題。

你應該使用絕對路徑圖標:

link :rel => 'icon', :href => '/favicon.ico', :type => 'image/x-icon' 

您應仔細閱讀文件爲二進制:

FAVICON = File.binread('favicon.ico') 
+0

讀取文件.binread是解決方案。謝謝! – timebandit 2013-05-04 18:46:27

0

我把你的代碼和它的工作蠻好的,那是以前我取消了鏈接指令的註釋:瀏覽器只是非常熱衷於獲取/favicon.ico。 你的問題是你的favicon從來沒有出現過,或者你的原始圖標現在頑固地拒絕改變?

+0

我使用了上述解決方案,並且我也重新啓動了瀏覽器。這似乎是訣竅。謝謝! – timebandit 2013-05-04 18:47:42