Adding a favicon to your Rails 7 app

November 27, 2023

It's super easy to do with Rails. Just make the image you would like to be your favicon. I would suggest a square png file.

Then, upload the file to your app/assets/images folder.

image-folder-1.png

Next, add the code to display your favicon in the head section of your application layout file. In my case, I have a scripts partial that gets called in the head of multiple layouts that I use. That way, I just need to add any new code that needs to be in the head section of every page in the scripts partial. But, if you just have the main application layout, simply add this to your head section.

<%= favicon_link_tag asset_path('your-image.png') %>

And that's it. Once you refresh, you should see your new favicon in the browser tab, just like below.

image-favicon.png

Comments

You must be logged in to comment.