tomkr4l / font_awesome5_rails

font_awesome_5_rails is font awesome 5 gem bundled for rails asset pipeline
https://fontawesome.com/
MIT License
158 stars 25 forks source link

Constants don't load properly in Rails 6.1 #62

Closed moveson closed 3 years ago

moveson commented 3 years ago

I've been using font_awesome5_rails for years with no problems. Recently I upgraded my app to Rails 6.1. There are no problems on initial load of the server, but if I make changes anywhere in the code without restarting the server, I get this error:

uninitialized constant FontAwesome5::Rails::IconHelper::FaIconParser

This is the case even if the code I change has nothing to do with this gem.

I'm guessing there's an incompatibility with zeitwerk somewhere in the gem, but I'm not sure how to fix it.

tomkr4l commented 3 years ago

Hello @moveson, I'm pretty sure this will be problem with zeitwerk as you said. There seems to be problem with naming convention in my gem. Unfortunately I have problem to simulate this on newly created rails 6.1 app. What is output when you run rake zeitwerk:check?

I've created new branch zeitwerk, which I believe should fix the issue. Could you try it and confirm it solved your problem? Just add to your gemfile:

gem 'font_awesome5_rails', git: 'https://github.com/tomkra/font_awesome5_rails', branch: 'zeitwerk'

Thank you.

moveson commented 3 years ago

Sorry for the slow reply. I tried the new branch and it does not solve my problem. This is an older Rails app (originally 4.2) so my setup isn't as clean as a new 6.1 app would be.

When I run rake zeitwerk:check I get the following output:

Please, enable :zeitwerk mode in config/application.rb and try again.

Here is my repo if that's helpful: https://github.com/SplitTime/OpenSplitTime

moveson commented 3 years ago

I've now switched over to using zeitwerk in my app, and the problems in the dev environment are worse. Now I'm getting uninitialized constant FontAwesome5::Rails::IconHelper::FaIconParser anytime I try to load a page that uses the fa_icon helper method, even directly after a server restart.

The problem seems to be a mismatch between the constant namespacing and the directory structure of the gem. I've got it working in a patched version locally. I'll put up a PR shortly.

moveson commented 3 years ago

https://github.com/tomkra/font_awesome5_rails/pull/64/files

tomkr4l commented 3 years ago

Should be solved in 1.4.0. Thank you once more.