Questions tagged [zeitwerk]
68 questions
3
votes
1 answer
Auto/Eager load a directory outside of /app
In Rails application(Rails 6) I have created a directory in the root of rails application - outside of /app folder. I want to try to keep some logic outside of Rails web framework.
- rails_root
- app/
- models/
- controllers/
- lib/
…

Basin
- 887
- 1
- 14
- 28
2
votes
1 answer
Zeitwerk + Rails 6.1 with model and namespaced subclasses, "earlier autoload discarded"
After researching this on SO and a very similar issue in Rails' GitHub issues, I'm still unclear what's wrong. My namespaced model subclasses are not eager-loaded, but I believe they are declared correctly and in the right place.
They do seem to be…

nimmolo
- 191
- 3
- 14
2
votes
2 answers
Why is Rails/Zeitwerk expecting `burgerfrenchfry_coupon.rb` to define the constant `BurgerFrenchfryCoupon`?
I'm working on upgrading a large legacy Rails application from 5.2 to 6.0. In the process of fixing the autoload paths, I've run into an issue where Rails/Zeitwerk seem to be breaking their own rules about how the names of constants are defined in…

RickyTomatoes
- 722
- 6
- 11
2
votes
1 answer
Zeitwerk: Add engine/gem directories to autoload path of parent Rails app
I'm trying to switch to Zeitwerk in an existing, older Gem (Rails::Engine). Until now all files have been manually required and autoloaded. Plus the engine's lib-folder was added to autoload_paths via config.autoload_paths += paths["lib"].to_a in…

Tococorocko
- 78
- 7
2
votes
1 answer
uninitialized constant when reloading after enabling zeitwerk
Having some trouble working out the migration from Classic to Zeitwerk.
After enabling zeitwerk and running rails s, everything seems to work. Then after saving a .rb file and refreshing, I'm seeing an "uninitialized constant" error when trying to…

Roy Kolak
- 605
- 1
- 6
- 18
2
votes
1 answer
Classes with the same name results in uninitialized constant when using Rails 6 Zeitwerk
I'm having issues with zeitwerk where I can't access another models constant that shares the same name. For example:
in /app/models I have a worker.rb file with a constant RETRY_COUNT
class Worker < ApplicationRecord
RETRY_COUNT = 10
end
and in…

cvdv
- 2,691
- 3
- 14
- 29
2
votes
2 answers
Rails Zeitwerk `Wrong constant name` for javascript
Using Rails 6
I have a folder like so app/client/javascript/config/editor/syntax-highlighting
2 files in…

GN.
- 8,672
- 10
- 61
- 126
1
vote
1 answer
NameError (uninitialized constant Error) in Rails 7
I recently upgraded my rails application to rails 7 and after upgrading when I try to call the call from the lib folder I am getting this error NameError (uninitialized constant Error)
I have following file structure in the lib folder
lib
-> a
->…

Ghanshyam Anand
- 11
- 1
1
vote
1 answer
How to properly extend a module in Rails 6 using Zeitwerk
I'm in process of switching from classic autoloader to zeitwerk. And I've faced this problem:
NameError: uninitialized constant SomeHelper::Forms
I have a helper module SomeHelper in app/helpers/some_helper.rb which contains this code
module…

A. Askarov
- 625
- 7
- 13
1
vote
1 answer
Canonical way to reload classes/constants used within package configs
I have been getting the familiar DEPRECATION WARNING: Initialization autoloaded the constant error message for one of my apps.
I have a Rails6 app that uses the dragonfly gem which comes with image resizing processors, and I use them for…

andyroberts
- 3,458
- 2
- 37
- 40
1
vote
1 answer
NameError: uninitialized constant Matrix only in rails console
When I try using Matrix or Vector standard Ruby's classes in Rails 7 app I receive NameError:
rails c
Loading development environment (Rails 7.0.3.1)
[1] pry(main)> Matrix
NameError: uninitialized constant Matrix
Explicit require doesn't help:
[3]…

Oleg Antonyan
- 2,943
- 3
- 28
- 44
1
vote
1 answer
Zeitwerk not autoloading models in rails 7
I recently upgraded my Rails version of my application from 6.1 to 7 and I am facing one issue with zeitwerk. I was also using the zeitwerk in my rails 6.1 which was working fine but suddenly something is breaking when I upgraded it to rails…

Dev V
- 85
- 1
- 10
1
vote
2 answers
Zeitwerk::NameError due to Module name in rails 7
I recently upgraded my application from rails 6 to 7 and I am facing one issue due to zeitwerk naming convention. I have a below file which I want to autoload:
app/models/dw/hospital.rb
module DW
class Hospital < DataWarehouse
def…

Dev V
- 85
- 1
- 10
1
vote
1 answer
Zeitwerk doesn't requires lib classes properly in Rails 6.1.6
I'm trying to update my app from Rails 5.2 to 6.1, and use Zeitwerk autoload, and I am having some issues for autoloading /lib classes.
I included this in config/application.rb:
config.load_defaults 5.2
config.autoloader =…

Alexandre Magro
- 1,131
- 2
- 10
- 22
1
vote
1 answer
Zeitwerk needs to reload every change
In development enviroment, when using zeitwerk, every change in ruby code needs to restart the server, because zeitwerk isn't loading classes defined in mygem. I have a gem, used by my company that uses rails models. And some of that models are…

Roberto Furtado
- 43
- 1
- 7