Looking for way to load just selected models inste

2019-08-08 19:44发布

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条回答
贼婆χ
2楼-- · 2019-08-08 20:20

You could do task :winner do and then require the modules/models in our outside the task.

查看更多
登录 后发表回答