The following ruby code helps us to get the favicon from the given url:
For this I have written a icon.rhtml file which contains the input field to get the url from the user
icon.rhtml
<form>
URL: <input type=”text” name=”main_url” />
<br/>
Favicon URI: <%=@url%>
<br/>
Favicon: <img src= <%=@url%> style=”width: 16px; height: 16px; border: 0; vertical-align: -4px;” alt=”">
</form>
in the corresponding controller file icon_controller.rb
def icon
require ‘open-uri’
begin
main_url = params[:main_url];
f = open(main_url)
rescue
err = $!
err_s = err.to_s
end
if err_s == nil
a = f.read
s= a.slice(/link.*rel\=.*shortcut.*\”/)
if s != nil
exp = s.split(“href=”)
exp1 = exp[1].split(‘”‘)
exp2 = exp1[1].split(“http:”)
if exp2[0] != “”
@url = main_url+exp1[1]
else
@url = exp1[1]
end
else
@url = main_url+”/favicon.ico”
end
else
end
end
