Zeitwerk and extentions

51 Views Asked by At

I'm having some troubles with Zeitwerk when migrating to Rails 7.

I got:

# config/initializers/monkey_patches.rb:4
Dir[Rails.root.join('lib', 'extensions', '*.rb')].each { |f| require f }

String.include Extensions::String
Devise::FailureApp.send :prepend, Extensions::Devise::FailureAppCustom

Extensions::Devise::FailureAppCustom is defined undes lib/extensions/devise/failure_app_custom.rb

and I got NameError Exception: uninitialized constant Extensions::Devise

I thought it was because the module Extensions was not created so I've added it before

module Extensions; end

Still not working.

I made tons of update having different errors like

uninitialized constant Devise::FailureApp

I also have config/initializers/zeitwerk.rb

where I'm defining

# Fixing loading issue
# https://stackoverflow.com/a/71574682/2616474
Rails.autoloaders.main.ignore(Rails.root.join("app/middleware"))

ActiveSupport::Dependencies.autoload_paths << 'app/deliveries/concerns'
# lib/extensions/devise/failure_app_custom.rb

module Extensions
  module Devise
    module FailureAppCustom

      protected

      def warden_message
        # Original checks `warden.message` first
        # We need to be able to force message without rewriting
        # the winning stragery of warden (Devise::Strategies::DatabaseAuthenticatable)
        @message ||= warden_options[:message] || warden.message
      end
    end
  end
end

I've read this point from @XavierNoria but I'm not able to fully understand how this should be declare properly.

1

There are 1 best solutions below

0
brcebn On

Basic issue.

Dir[Rails.root.join('lib', 'extensions','**', '*.rb')].each { |f| require f }

Only the first level of files were required. Just needed to add all of them below (**)