例弃用警告

问题描述:

我得到以下弃用警告:例弃用警告

DEPRECATION WARNING: The behavior of `changed?` 
inside of after callbacks will be changing 
in the next version of Rails. 
The new return value will reflect the behavior 
of calling the method after `save` returned 
(e.g. the opposite of what it returns now). 
To maintain the current behavior, use `saved_changes?` instead. 

此代码:

def send_devise_notification(notification, *args) 
    # If the record is new or changed then delay the 
    # delivery until the after_commit callback otherwise 
    # send now because after_commit will not be called. 
    if new_record? || changed? 
    pending_notifications << [notification, args] 
    else 
    devise_mailer.send(notification, self, *args).deliver_later 
    end 
end 

有人可以解释我用一个例子弃用警告?我不知道如果我理解正确的话做什么用The new return value will reflect the behavior of calling the method after "save" returned

意味着我可以现在只需更换changed?saved_changes??谢谢

据我了解,它是这样的。现在#changed?在回调后返回false,直到您更改属性。因此,#changed?记录在回调之后表现得像在刚刚通过执行#find(或者,如消息所示,如果在调用#save后有记录)获取记录。 #saved_changes?回答问题:#save的最后一次调用是否有任何更改?所以在我能想到的情况下,您可以在回调之后安全地切换到此方法。