我的控制器home_controller.rb
中有方法:
def send_letters
if Card.created_before(Time.now).any?
@users = User.all
@users.each do |user|
CardMailer.send_expired_cards(user.email).deliver_now
end
end
redirect_to root_path
end
并邮寄card_mailer.rb
:
class CardMailer < ApplicationMailer
default from: "new-cards@flashcards.com"
def send_expired_cards(email)
@email = email
@url = "http://flashcards.com"
@cards = Card.created_before(Time.now)
mail(to: @email,
subject: "Простроченные карточки на проверку от сайта Flashcards.com")
end
end
所有内容都配置为发送手动信件(我只需点击链接“发送电子邮件”,执行控制器方法send_letters)。工作良好。但我需要每天按照Heroku服务的时间发送这些电子邮件。