dimanche 27 août 2017

Example for deprecation warning

I get the following deprecation warning:

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. 

for this 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

Can somebody explain me the Deprecation Warning with an example? I'm not sure if I understand correctly what's meant with The new return value will reflect the behavior of calling the method after "save" returned

Can I now simply replace changed? with saved_changes?? Thanks

Aucun commentaire:

Enregistrer un commentaire