Skip to content

Instantly share code, notes, and snippets.

@sdsykes
Created October 8, 2011 08:17
Show Gist options
  • Save sdsykes/1272013 to your computer and use it in GitHub Desktop.
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
# 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