Reputation: 906
I'm trying to send emails when a certain attribute changes in my model.
My model has a string
which I set to hired
reject
seen
and notseen
.
For example, If the attribute gets changed to reject
I want to send an email, and if it's changed to hired
I want to send a different one.
In my model I have:
after_update :send_email_on_reject
def send_email_on_reject
if status_changed?
UserMailer.reject_notification(self).deliver
end
end
Which sends the email when the status gets changed regardless of what the status is. I don't know how to specify this. I have tried something like:
def send_email_on_reject
if status_changed?
if :status == "reject"
UserMailer.reject_notification(self).deliver
end
end
end
which just doesn't send the email.
I have been searching but cannot find any up to date similar questions/examples.
Thanks in advance.
Upvotes: 0
Views: 147
Reputation: 11421
def send_email_on_reject
if status_changed? && status == "reject"
UserMailer.reject_notification(self).deliver
end
end
Upvotes: 1