Ruby ActionMailer。发送到新电子邮件

时间:2017-10-26 04:35:49

标签: ruby-on-rails email

我正在尝试在邮件中设置一种方法,以便在两周后发送电子邮件。我无法从数据库中提取已创建的电子邮件并将其放入“mail(to:...)”中......如果我从控制台请求,我可以发送电子邮件。

所以我们的目标是,每次添加新位置时,都会在14天后将电子邮件发送到指定的电子邮件地址。 这是我的app / mailer。

class NotificationMailer < ApplicationMailer
    default from: "no-reply@xxx.com"

    def reminder(email)
        @email = email

        mail(to: @place.email,
            subject: "Reminder: your box is going to be picked up in fourteen days")
    end 
end

我的模特

class Place < ApplicationRecord
    belongs_to :user
    after_create :send_alert_email

    geocoded_by :address
    after_validation :geocode 

    validates :name, presence: true 
    validates :name, length: {minimum: 3,
     too_short: " %{count} or more characters are required."}
    validates :address, presence: true
    validates :phone, length: { is: 10}

    def send_alert_email
        NotificationMailer.reminder(self).deliver(wait: 1.hour)
    end 

end

谢谢大家的帮助。

1 个答案:

答案 0 :(得分:1)

不应该吗?

def reminder(place)
    @place = place

    mail(to: @place.email,
        subject: "Reminder: your box is going to be picked up in fourteen days")
end 

不需要做数学,你可以使用wait: 14.days