[Ruby on Rails] How to Set favicon.ico with favicon_link_tag
I’ll introduce how to set favicon.ico using Ruby on Rails’ favicon_link_tag helper method.
Rails has a helper method called favicon_link_tag, so you can use this to set a favicon in template files.
I added favicon_link_tag ‘favicon.ico’ inside the head as follows:
app/views/layouts/application.html.haml
!!!
%html
%head
%meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
%title YourSite
= csrf_meta_tags
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload'
= javascript_include_tag 'application', 'data-turbolinks-track': 'reload'
= favicon_link_tag 'favicon.ico'
%body
= yield
Also, I saved the favicon file as favicon.ico directly under app/assets/images/.
You can also use favicon_link_tag by omitting the first argument, but explicitly writing ‘favicon.ico’ seems useful for grep searches later, so I configured it this way.
That’s all from the Gemba where I set favicon.ico using Ruby on Rails’ favicon_link_tag helper method.