在Rails 3.2.16中,此rake任务的执行因uninitialized constant
错误而中断,抱怨Model类MyModel
未知。
desc "some rake task"
task :do_it => :environment do
# do something depending on a model:
MyModel.each do |m|
# do something with model
end
# ...
end
答案 0 :(得分:0)
看起来根本原因是我在配置文件中启用了config.threadsafe!
。
要解决此问题,请执行以下操作:
# only enable threadsafe! mode if we are not running rake tasks
config.threadsafe! unless File.split($0).last == 'rake' # unless it's a rake task