Looking for way to load just selected models instead of all Rails environment in rake task

会有一股神秘感。 提交于 2019-12-11 13:58:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!