Cannot install forest admin - Zietwork error

I’m trying to install Forest Admin on a new rails application. I have them gem installed and I’m running rails g forest_liana:install {key redacted}

When I run this I get the following Zeitwork error

/Users/hummingbear/.rvm/gems/ruby-3.0.2/gems/zeitwerk-2.4.2/lib/zeitwerk/loader/callbacks.rb:18:in `on_file_autoloaded': 

expected file /Users/hummingbear/.rvm/gems/ruby-3.0.2/gems/forest_liana-7.0.0/app/services/forest_liana/forest_api_requester.rb 

to define constant ForestLiana::ForestAPIRequester, but didn't (Zeitwerk::NameError)

Context

Rails 6.1.4
Ruby 3.0.2
pg 1.2.3
postgres 13
forest_liana 7.0.0

Thanks!

Hi @KidA001 !
I’m not fluent un ruby, however I found this stackoverflow post maybe it can solve your issue…

Thank you - It seems like the forest gem has not yet been setup to work with Rails 6. Changing the config to use the old autoloader fixed Forest

Has anyone come up with better solutions here? I’m trying to install ForestAdmin on a pre-existing Rails app that uses Zeitwerk. Turning the loader back to “classic” isn’t really an option. I’m currently stuck trying to install ForestAdmin.

1 Like

I would appreciate a solution too. I’m using rails 7 and would like to take advantage of zietwork loading.

hello @KidA001

I can’t reproduce this issue on my end, but could you execute these 2 commands and share the result please.

bin/rails zeitwerk:check
bin/rails runner 'p Rails.autoloaders.zeitwerk_enabled?'

Is your rails 6 a fresh install or an old rails 5 you migrated to rails 6 ?

Actually it must have been my last project on rails 6. My current rails 7 is on zeitwerk with no issues. I’ll try with my old project and see.

Thanks for your assistance. I tried running both commands, and both commands failed with the error:

Just FYI, I am running Rails 6 at the moment, and Zeitwerk is definitely enabled.

expected file /tmp/volumes/gems/gems/forest_liana-7.4.5/app/services/forest_liana/ip_whitelist_checker.rb to define constant ForestLiana::IPWhitelistChecker, but didn't (Zeitwerk::NameError)

Hello @ryangerard

It looks like your rails6 doesn’t load correctly the ip_whitelist_checker file.

Could you add this line into your config/initializers/inflections.rb

Rails.autoloaders.main.inflector.inflect("ip_whitelist_checker" => "IpWhitelistChecker")
2 Likes