Skip to content

Instantly share code, notes, and snippets.

@bburdiliak
Created September 23, 2015 17:15
Show Gist options
  • Save bburdiliak/bef208807e8ba292e0c9 to your computer and use it in GitHub Desktop.
Save bburdiliak/bef208807e8ba292e0c9 to your computer and use it in GitHub Desktop.
Environment: Mongoid v. 4.0.0.rc1. Solves problem when running db:mongoid:create_indexes or any other mongoid rake task doesn't take into account models defined in engines used by your main application.
# main_app/lib/tasks/load_model.rake
namespace :db do
namespace :mongoid do
# include models from engine
task :load_models do
Scraper::Engine.config.paths['app/models'].to_a.each do |path|
preload = ::Mongoid.preload_models
if preload.resizable?
files = preload.map { |model| "#{path}/#{model}.rb" }
else
files = Dir.glob("#{path}/**/*.rb")
end
files.sort.each do |file|
require_dependency(file)
end
end
end
end
end
@TinNT
Copy link

TinNT commented Nov 16, 2015

Very nice! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment