Mason SB
Mason SB

Reputation: 525

Ruby ActionMailer. Sending to new email

I am trying to set-up a method in my mailer to deliver the email after two weeks. I am having trouble pulling the created email from the database and putting it in "mail(to: ...)" ... I can have emails sent out if I request it from the console.

So the goal is, every time a new location is added, an email will be sent to the given email address after 14 days. Here is my app/mailer.

class NotificationMailer < ApplicationMailer
    default from: "[email protected]"

    def reminder(email)
        @email = email

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

MY MODEL

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

Thank you guys for all the help.

Upvotes: 0

Views: 45

Answers (1)

Xavier Delamotte
Xavier Delamotte

Reputation: 3599

Shouldn't it be ?

def reminder(place)
    @place = place

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

And not need to do maths, you may use wait: 14.days

Upvotes: 1

Related Questions