Skip to content

Instantly share code, notes, and snippets.

@merbjedi
Created February 7, 2010 12:57
Show Gist options
  • Save merbjedi/297420 to your computer and use it in GitHub Desktop.
Save merbjedi/297420 to your computer and use it in GitHub Desktop.
Ok, so I want to wrap all my classes in a module, so they dont pollute the global namespace,
and I can later refactor them into reusable apps.
Say the name of my app is MobileBookstore. The only way to work around load_missing_constant
is to organize your app like this:
app/
helpers/
mobile_bookstore/
books_helper.rb
controllers/
application_controller.rb
mobile_bookstore/
books_controller.rb
models/
mobile_bookstore/
book.rb
why do I need 3 separate mobile_bookstore folders? Having to repeat it over and over is a drag.
I'd like to organize it like such:
app/
helpers/
books_helper.rb
controllers/
application_controller.rb
books_controller.rb
models/
book.rb
book.rb looks like this
class MobileBookstore::Book
# ... model contents ...
end
Simple solution, ActiveSupport::Dependencies::Blamable::load_missing_constant should provide an
exception if you wrap your file within your Application namespace's module. So if your app name was
"MobileBookstore" and your model name was "Book", it would check for the constants "Book" and
"MobileBookstore::Book" before exploding. One line fix.
On a related note, how do I avoid needing an ::ApplicationController? How can I change it to
MobileBookstore::ApplicationController instead?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment