Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

/favicon.ico Being Appended to Rails 4 Routes

This is a strange one. I started a new Rails 4 application today and then created a resource called transfer_functions. When I hit a url like localhost:3000/transfer_functions/1 it appends /favicon.ico to the end of it and I get this error in the server console.

ActionController::RoutingError (No route matches [GET] "/transfer_functions/1/favicon.ico"):

Any ideas? Thanks!

The app is using 'turbolinks' gem.

Update:

I'm using Twitter Bootstrap and created the application layout with the respective generator. I removed this line from my application.html.haml file and it fixed the problem.

%link(href="favicon.ico" rel="shortcut icon")

Not sure that I understand why that caused a problem.

like image 231
mikeborgh Avatar asked Mar 09 '13 07:03

mikeborgh


1 Answers

The reason that error popped up was because the line you removed is essentially saying "look for a favicon.ico in the current directory". That haml code you posted renders into html that looks something like <link href="favicon.ico...".

The way you should handle a favicon is like this:

  1. Put your favicon file in this directory: your_webapp/app/assets/images/

  2. Edit your_webapp/app/views/layouts/application.html.hamland add the following under the document's head: = favicon_link_tag

Rails will use the asset pipeline to serve the favicon just like any other site asset. You just need the file name, and don't need to include the images folder within the url.

If you're interested in the docs: http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-favicon_link_tag

You can also add in whatever you need to rel

like image 94
Mario Zigliotto Avatar answered Oct 11 '22 11:10

Mario Zigliotto