我有一个 rake 任务,它仅循环遍历我的所有产品并在产品保存时增加一个计数器。然后它打印出那个计数器。我如何测试什么号码呢puts
?
task(:resave_every_product => :environment) do
total_products = 0
counter = 0
all_products = Product.find(:all)
puts "done loading all products"
puts "starting resaving..."
all_products.each do |product|
puts "current product is #{product.id}" if (counter%1000 == 0)
counter += 1 if product.save
end
puts "done resaving products."
puts "total products - #{all_products.size}"
puts "products resaved - #{counter}"
end