问题
in classic rake example we can load all rails environment with all models in taks with:
desc "Pick a last user name"
task :winner => :environment do
puts "Last user: #{User.last.name}"
end
I have very large rails project so it takes a lot of time to load all models and dependencies. Is any way to load rails with just specific model or set of models?
I'm about to write custom rails loader but don't want to invent bycicle ;) Maybe some gem or good custom loader example already exist?
I think it would be useful for some cases of resque workers as well. Thanks!
回答1:
You could do task :winner do
and then require the modules/models in our outside the task.
来源:https://stackoverflow.com/questions/9390775/looking-for-way-to-load-just-selected-models-instead-of-all-rails-environment-in