class Legacy def self.clear_period begin count = 0 puts '---------------------' Course.transaction do Course.all.each do |course| if course.class_period =~ /^\D*$/ count += 1 puts "[#{course.id}]: #{course.name}" puts "period #{course.class_period} ===> 0" puts '---------------------' course.class_period = '0' course.save end end # each end end # transaction end puts "clean period count: #{count}" rescue Exception => ex puts "*** transaction abored!" puts "*** errors: #{ex.message}" end end end