我想在Rails中使用迁移运行Rake任务。每次执行
当前的Rake任务如下所示。
rails db:migrate
命令时,任务将通过迁移运行。当前的Rake任务如下所示。
namespace :task_for_log do
desc 'This task sets current date as a default for logs where log_date is nil'
task set_by_default_date_of_log: :environment do
Log.where('log_date IS NULL').each do |log|
log.update_attributes(log_date: log.created_at.to_date)
end
end
end
我该如何使用迁移文件来运行该任务?