簡體   English   中英

Ruby在軌道上。 回調,指定更改的屬性

[英]Ruby on rails. Callbacks, specifying changed attribute

當模型中的某些屬性發生更改時,我正在嘗試發送電子郵件。

我的模型有一個string ,我設置為hired seennotseen seen reject notseen

例如,如果屬性更改為reject我想發送一封電子郵件,如果屬性更改為已hired我想發送另一封電子郵件。

在我的模型中,我有:

after_update :send_email_on_reject

def send_email_on_reject
    if status_changed?
      UserMailer.reject_notification(self).deliver
    end
  end

無論狀態如何,狀態更改時都會發送電子郵件。 我不知道該如何指定。 我已經嘗試過類似的東西:

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

只是不發送電子郵件。

我一直在搜索,但找不到任何最新的類似問題/示例。

提前致謝。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM