【发布时间】:2022-10-15 01:02:39
【问题描述】:
我正在尝试制作一个 rake 任务以在 heroku 上使用调度程序运行它,但首先我在本地进行测试,所以我有一种方法可以检查这样的投票状态
def check_status
if Date.today.between?(self.start_date, self.expiration_date)
self.poll_active = true
else
self.poll_active = false
end
end
它工作得很好,但现在我想要这个确切的方法来运行它的任务。
我创建我的任务文件
namespace :change_poll_status do
task :poll_status => :environment do
if Date.today.between?(Poll.start_date, Poll.expiration_date)
Poll.poll_active = true
puts "It works"
else
Poll.poll_active = false
puts "no"
end
end
end
但是当我运行rake change_poll_status:poll_status
什么都没有发生,它只是跳过,就像没有什么可以运行,没有错误,什么都没有。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-6 ruby-on-rails-6.1