Search code examples
ruby-on-railsrubyerbfavicon

Ruby on Rails favicon not loading


This <% favicon_link_tag '/favicon.ico' %> is in the head section of my application.html.erb file within my layouts folder.

My favicon is stored in assets, and is not rendering in the browser tab.

Any idea why this is happening? Am I doing something wrong here?

Thanks.


Solution

  • You should look at the output Rails is sending to your browser. You'll find no mention of a favicon, as you're not actually outputting anything.

    favicon_link_tag is a plain old Ruby function. It returns a value, which is a string, containing the HTML markup for a link tag to your favicon. You're taking that value, and throwing it away.

    You need to output that value, and in ERB, you do that with <%=, not <%.

    Replace your <% favicon_link_tag ... %> with <%= favicon_link_tag ... %> and you'll find that you suddenly have a <link rel="shortcut icon" ... /> appearing in the HTML being output by your Rails app.