Setting Your Favicon in Ruby on Rails Apps

image_pdfimage_print

Favicons are this nifty little icons on the tab of your browser to help give a little personalized identity rather than the blank page one which is the default

This is one of the super fast things to fix yet I forget every time I build out a Rails app. Favicons can be created with a plethora of different sites. I’m old school and keep using DynamicDrive (http://tools.dynamicdrive.com/favicon/) as it has limited advertising and junk on the site.

The code block is super easy to remember…except when I need to remember it, so here it is:

<%= favicon_link_tag asset_path('image-name.ico') %>

Here are the steps to set up your favicon in your Rails app:

  1. Generate your icon
  2. Copy the icon to the app/assets/images folder
  3. Create the pointer in the HEADsection of your app/views/layouts/application.html.erb file as shown here:

Reload the server your server and you’re off to the races!  Once you restart your app you should see your new icon appear. There may be some delay because some browsers (Chrome being the main culprit) believe in caching everything to save you time on loading. This creates problems because sometimes the cache invalidation takes a while when you legitimately want to see an update.

This will be the end result:

Hopefully this is helpful and saves you a little hunting for the solution.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.