Questions tagged [zeitwerk]
68 questions
11
votes
2 answers
Rails 6 Zeitwerk "DEPRECATION WARNING: Initialization autoloaded the constants..." but I can't figure out where?
I swear I've read the docs and I think I have a basic understanding of the principles, but I can't for the life of me figure out where I'm loading these constants inappropriately.
I'm working to upgrade an app that was originally Rails 5.2
I'm…

Chiperific
- 4,428
- 3
- 21
- 41
10
votes
2 answers
ERROR: Error installing rails zeitwerk requires Ruby version >= 2.4.4
I recently changed my laptop and tried installing rails with
gem install rails
and I got this error
ERROR: Error installing rails:
zeitwerk requires Ruby version >= 2.4.4.
I have installed ruby version 2.4.4, 2.5.7, and 2.6.5 and I'm still…

Ayogu Chibueze
- 211
- 1
- 4
- 10
7
votes
1 answer
How can I extend gem class in Rails 6/Zeitwerk without breaking code reloading?
How do I extend a class that is defined by a gem when I'm using rails 6 / zeitwerk?
I've tried doing it in an initializer using require to load up the class first.
I've tried doing it in an initializer and just referencing the class to let…

nbrustein
- 727
- 5
- 16
6
votes
3 answers
Rails 6+, zeitwerk autoloader and namedspaced constants
The Rails 6+ default autoloader is zeitwerk, which seems like a great improvement over previous approaches.
However, zeitwork follows the convention for Rails projects that anything in app/* is autoloaded and doesn't need to be namespaced.
This…

Dan L
- 4,319
- 5
- 41
- 74
5
votes
2 answers
rails 7 zietwerk constants not found
I'm upgrading our app from rails 6 to 7, I was using zeitwerk instead of the classic autoloader with rails 6 without any issues, now without any changes to the folder/file naming convention or structure it fails to find any classes/modules inside…

Subash
- 3,128
- 6
- 30
- 44
5
votes
1 answer
Rails 6 Autoload Not Finding Class
I'm attempting to upgrade from Rails 5 to 6. I did the upgrade steps including adding this:
# config/application.rb
config.load_defaults 6.0
I have this class:
# lib/notification/auto_thank.rb
module Notification
class AutoThank
def perform
…

Tim Scott
- 15,106
- 9
- 65
- 79
4
votes
2 answers
Rails: Auto-reload gem files used in dummy app
When developing a gem, I often use a dummy rails app that requires the gem in order to try out gem changes as I go. Also, I use the same dummy app for integration tests.
Usually, I have the gem in
~/rails/foo_gem
and the associated dummy app…

fiedl
- 5,667
- 4
- 44
- 57
4
votes
1 answer
Why Rails6+ started adding activesupport requires in config/environments/* by default?
I'm a bit late with Rails version upgrade. What surprised me was a bunch of active_support requires in config/environment/* files generated by Rails.
What are they for? Does it have something to do with Zeitwerk that was introduced in Rails6?
I…

BinaryButterfly
- 18,137
- 13
- 50
- 91
4
votes
0 answers
Rails 6 doesn't load engine modules and classes (Zeitwerk?)
At work, we both have an Rails application 'MyApplication' and an gem/ engine 'MyEngine' which provides utilities to MyApplication. One of the purposes of MyEngine is to monkey patch ruby base classes and extend them with functionality relevant to…

Jurr
- 41
- 3
4
votes
2 answers
There is a programmatical way to detect Zeitwerk::NameError when upgrading to Rails 6?
I am currently migrating an old Rails application to Rails 6.
It seems that some files in the project are not consistent with the classes defined in it.
I don't see this error when running the tests of the application, but after deploy I receive…

mabe02
- 2,676
- 2
- 20
- 35
4
votes
2 answers
Namespacing service objects in Rails 6 with Zeitwerk autoloader
Rails 6 switched to Zeitwerk as the default autoloader. Zeitwerk will load all files in the /app folder, eliminating the need for namespacing. That means, a TestService service object in app/services/demo/test_service.rb can now be directly called…

phoxley
- 464
- 8
- 19
4
votes
2 answers
Uninitialized Constant Error When Switching To Zeitwerk
I currently have the following files in the jobs directory:
# app/jobs/importer.rb
module Imporer
def self.valid_importers
# Do stuff
end
end
# app/jobs/importer/custom_import_job.rb
class Importer::CustomImportJob < ApplicationJob
def…

Ahmad Abdel-Yaman
- 113
- 1
- 8
3
votes
1 answer
Questions about Reloading and Engines in rails with Zeitwerk autoloader
Background:
I am getting some reloading errors in development when switching to Zeitwerk for a rails 6.0 application that uses an engine (thredded). I'm also a developer on thredded, so want to understand this fully before committing any apparent…

Tim Diggins
- 4,364
- 3
- 30
- 49
3
votes
1 answer
Rails 7 and Zeitwerk not loading in tests
My Rails 7, Ruby 3.1 App has a simple test that is failing. I am not understanding why.
In my App I have added a support directory labelled stuff, which has some GraphQL code in it. So in my tests, I want to do a GraphQL.test(foo: "me", bar:…

David Lazar
- 10,865
- 3
- 25
- 38
3
votes
1 answer
Rails 6: Automatically reload local gem on change
I am developing a Rails 6 app and a Gem in parallel.
In the past, I used the require_reloader Gem so that Rails would reload the Gem when any files changed in the Gem's local directory.
With Zeitwerk becoming the new loader in Rails 6, this Gem…

Christopher Oezbek
- 23,994
- 6
- 61
- 85