0

I've already installed it with Yarn and also de font-awesome-rails gem. Also included de CDN on the head tag and import "@fortawesome/fontawesome-free/css/all" on application.js. I'm trying to render the <i class="fab fa-github"></i> icon, among others I've tried, on my landing page. However, none of these steps are rendering any icons from my view files. What could be the problem?

Mik
  • 31
  • 5
  • Try import "@fortawesome/fontawesome-free/js/all" in your application.js instead of the css import. Also: I don't think you need the CDN link. – Drew Johnston May 13 '21 at 12:25
  • @DrewJohnston Thanks, but didn't work either. – Mik May 13 '21 at 20:20
  • 1
    I just retested on a fresh project, Rails 6.1. The only steps I needed were: "yarn add @fortawesome/fontawesome-free", then in app/javascript/packs/application.js add the line import "@fortawesome/fontawesome-free/css/all" at the bottom. The gem is not necessary unless you want to use the helpers (though not sure if that will work with webpacker anyway), and when you install the libraries locally you dont need the CDN. Are you able to use any other JS libaries? Perhaps your webpacker config is incomplete? – Drew Johnston May 13 '21 at 23:21
  • @DrewJohnston Already installed the latest webpacker gem, still no icons showing up. It's weird because on my last Rails project the icons were rendering normally. – Mik May 14 '21 at 21:52
  • 1
    Here are a few things to try: Do you have stylesheet_pack_tag and javascript_pack_tag at the top of your application.html.erb? Are other css and js assets beside fontawesome loading and working? When running `bin/webpack-dev-server` are there any error messages? – Drew Johnston May 15 '21 at 01:26

1 Answers1

0

Install gem "font-awesome-rails", then in erb file, change:

<i class="fab fa-github"></i>

To:

<i class="fa fa-github"></i>

Or use this helper:

<%= fa_icon "github" %>

The github awesome icon will show.

protoproto
  • 2,081
  • 1
  • 13
  • 13
  • 1
    Add my skype xprotoprotox, I will check it for you! – protoproto May 14 '21 at 22:09
  • 1
    Or create fresh rails project, then apply my guide. This code I tested in my computer. It works fine! – protoproto May 14 '21 at 23:02
  • Sorry for the delay. I'm finally back to this project, but I decided to create a new one from scratch. The icons are now being rendered, I just don't know why/how. Anyway, thanks everyone. – Mik May 29 '21 at 03:16