简体   繁体   中英

Ruby on rails. Callbacks, specifying changed attribute

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.

def send_email_on_reject
  if status_changed? && status == "reject"
    UserMailer.reject_notification(self).deliver 
  end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM