#coding=utf-8 namespace :exercise_publish do desc "publish exercise and end exercise" task :publish => :environment do exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) exercises.each do |exercise| exercise.update_column('exercise_status', 2) end end task :end => :environment do exercises = Exercise.where("end_time <=? and exercise_status = 2",Time.now) exercises.each do |exercise| exercise.update_column('exercise_status', 3) end end end