Created
October 8, 2011 08:17
-
-
Save sdsykes/1272013 to your computer and use it in GitHub Desktop.
Fix for mongoid uninitialized constant errors from loading everything in lib in mongoid.rb in initializers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# initializers/mongoid.rb | |
# for when files in lib depend on or inherit from other files in lib | |
def do_require(file) | |
begin | |
require file | |
rescue NameError => e | |
e.message =~ /constant (\w+::)*(\w+)$/ | |
if $2 | |
do_require($2.underscore) | |
retry | |
end | |
end | |
end | |
Dir[Rails.root + 'lib/**/*.rb'].each do |file| | |
do_require(file) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment