How to fix favicon error in Rails

RubyPlus uses Amazon Cloudfront as the CDN. All the favicons for different devices and sizes are handled by using:


I have observed some requests get the error:

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

in the log files. In the page source, the favicon helper generates:

<link rel="shortcut icon" type="image/x-icon" href="/assets/favicon-b742c2941.ico" />

The signature changes if I make any modification to the assets. The users who have bookmarked before I used the CDN are still looking for the old favicon. Since it is no longer available, it crashes. This is bad for user experience. Add a favicon method in welcome controller.

def favicon
  send_file 'public/favicon.ico', type: 'image/x-icon', disposition: 'inline'

This method renders the favicon image inline. Define the route in config/routes.rb:

get 'favicon', to: "welcome#favicon"

Make sure you have favicon.ico in public/images folder. Now if you click the favicon, you will see the favicon rendered on the browser.


Render image with Rails controller

Related Articles

Software Compatibility Best Practices

I spoke to some of the most talented and experienced software developers. I have created a guide that is filled with valuable insights and actionable ideas to boost developer productivity.

You will gain a better understanding of what's working well for other developers and how they address the software compatibility problems.

Get the Guide Now