0

-je obtenir l'avertissement suivant deprecation:Exemple d'avertissement deprecation

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. 

pour ce code:

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 

Quelqu'un peut me expliquer l'avertissement de Obsolescence un exemple? Je ne sais pas si je comprends bien ce que est censé avec The new return value will reflect the behavior of calling the method after "save" returned

Puis-je remplacer maintenant simplement changed? avec saved_changes?? Merci

Répondre

0

Si je comprends bien cela fonctionne comme ça. Maintenant, #changed? renvoie false après les rappels jusqu'à ce que vous changiez un attribut. Donc, #changed? sur un enregistrement se comportent dans les rappels après, comme si vous venez de récupérer un enregistrement en faisant #find (ou, comme le dit le message, si vous avez un enregistrement après avoir appelé #save). #saved_changes? répond à la question: est-ce que le dernier appel à #save a été modifié pour changer? Donc, dans les cas je peux penser à vous pouvez passer en toute sécurité à cette méthode dans les rappels après.