I tried config.autoload_paths += Dir["#{config.root}/lib/**/"]
and config.eager_load_paths += Dir["#{config.root}/lib/**/"]
but keep getting the uninitialized constant
error.
I assume this has to do with dependency_loading
being disabled as config.threadsafe!
is now the default in Rails 4.
So what's the proper way and thread safe way to eager/autoload stuff from your /lib directory?
Update: The /lib structure
lib/car.rb:
module Car
CAR_TYPES = %w[volvo saab]
end
lib/car/volvo.rb:
module Car
class Volvo
end
end
The error thrown is NameError (uninitialized constant Car::CAR_TYPES)
Update 2: rails c
:
Car.class
=> Module
Car::CAR_TYPES
=> NameError: uninitialized constant Car::CAR_TYPES
Update 3: Interestingly enough, Car::Volvo.new
works, but Car::CAR_TYPES isn't possible to reference.