How to add favicon in rails 3.2

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

Answer

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 = ""

Attribution
Source : Link , Question Author : noob , Answer Author : Dennis

Leave a Comment