When storing files in a custom directory (Eg: app/presenters/
), how do you ensure that namespaced classes are loaded?
For example, if you have:
- app/models/mega_menu.rb
- app/presenters/catalog_presenter.rb
- app/presenters/mega_menu/catalog_presenter.rb
Rails fails to load MegaMenu::CatalogPresenter
:
CatalogPresenter.new
=> #<CatalogPresenter:0x85bca68 @_routes=nil>
MegaMenu::CatalogPresenter.new
(irb):3: warning: toplevel constant CatalogPresenter referenced by MegaMenu::CatalogPresenter
=> #<CatalogPresenter:0x85750a0 @_routes=nil>
I've created a sample Rails 3.2 app that reproduces this problem.
In config/application.rb
, the app's configured to load files in app/presenters/
.