I have this class:
# app/events/new_request.rb
class Events::NewRequest
end
And I added that folder to the autoload:
# config/application.rb
config.autoload_paths += %W( events/ )
And when running rails c
:
> Events::NewRequest
NameError: uninitialized constant Events
The thing is that if I don't use the namespace "Events" when defining the class, it autoloads the class successfully.
module Sandbox
class Application < Rails::Application
config.autoload_paths += [config.root.join('app')]
end
end
This will let Rails autoload Events::NewRequest
from app/events/new_request.rb
.
irb(main):001:0> Events
=> Events
irb(main):002:0> Events::NewRequest
=> Events::NewRequest
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With