I know new rails apps come with an empty favicon.ico file. I want to know how I go about adding a favicon. I know you can use the favicon_link_tag
helper, but I am not sure how to populate the favicon.ico file. Do you use favicon generators? If so, which one is best?
I also want to be able to cache it, does rails do that automatically as well?
Thanks
Simply add this to the <head></head>
section of your layouts:
<%= favicon_link_tag 'favicon.ico' %>
Place the favicon.ico image in /app/assets/images/
if you are using the asset pipeline, and in /public/images/
if you are not.
Also, there is a bug if using Ruby 2.0 with Rails 3.0.20 (and maybe also 3.0.x), that will throws an exception when trying to render favicon.ico.
The fix is to place the following code into application_controller.rb:
config.relative_url_root = ""
generate your favicon for example here: http://www.favicon.cc/ and put in to public/ directory
UPDATE Favicon in public folder is not precompiled and it may be cached for a long time. It looks like it is better to use favicon_link_tag to avoid favicon updating problems. I do not know browsers needed favicon in root. According to favicon wiki all modern browsers maintains
<link rel="shortcut icon" href="favicon path" /> (favicon_link_tag)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With