Rails and favicon.ico

23Feb07

I had never used a favicon for a site before.  I just added one to my upcoming quizical.net site. I ran into one small problem that I thought I would add here.

I created a 16 x 16 icon, named it favicon.ico and added it to my public folder (not public/images). Yet, the icon was not showing up in my browser.

Some poking around revealed that I must add the following between my document head:

<link rel="shortcut icon" href="/favicon.ico" />

Once I added that, it works fine. Easy.



10 Responses to “Rails and favicon.ico”

  1. 1 Jess

    Can I ask which document you inserted the code into? I keep placing it into my header.php doc but it isn’t showing up.

    Appreciate it in advance.

    Thanks!

  2. Hi Jess,

    These instructions are far a rails application. It sounds like your app is php. To answer your question though, I put the above link in my main layout file.

  3. 3 costa

    hi!
    it wouldn’t work if you’re using resources in your project.
    in this case you have to generate url relativ to the resource.

  4. 4 tim

    Thanks for this tip! That worked for my app. Strangely, my favicon showed up in the development environment without me having to do this – I only needed to do it in production…

    Any ideas why that would be?

  5. Good tip! I also tried to put favicon.ico inside public and it wasn’t working!
    Thanks!

  6. 6 Giovanni Catalano

    Thanks.

  7. 7 Omaer

    Ummm, you don’t really need to add this to the website – adding favicon.ico to the public folder is enough. The reason the favicon doesn’t show up is that most browsers cache the image. And for some reason, clearing the cache doesn’t always seem to work with the favicon. Try running the rails server with a different port number, and load that port. The new favicon.ico should show up.

    Eg. By default, rails runs the server at port 3000. Try changing the port to something you haven’t used before – run the app as
    RAILS 3: rails server -p 12345
    RAILS 1/2: ruby script/server -p 12345

    Then load the site at localhost:12345 in your web browser. The new favicon should be there. The next time you change the favicon, also change the port to something other than 12345 and it should reflect the changes.

    However, your method is good to know as well – thanks!

  8. 8 Patrick

    Clearing the browser cache worked for me, thanks!

  9. @steveodom this should go in your HTML element

  10. Just throw the favicon.ico in your public file and Rails will automatically bring it up. Even with 3.1


Leave a comment