Rails 5.1.1 deprecation warning changed_attributes

Almaron picture Almaron · Jun 19, 2017 · Viewed 7.9k times · Source

I've just upgraded from Rails 5.0.0 to 5.1.1 and started getting a ton of deprecation warnings like this:

DEPRECATION WARNING: The behavior of changed_attributes 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.transform_values(&:first) instead.

and this:

DEPRECATION WARNING: The behavior of attribute_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_change_to_attribute? instead.

I don't use those methods explicitely anywhere in my project and the warnings are pointing mostly at create and update calls on my models.

I believe it has something to do with my validations and after_update and after_create callbacks where I use confitions like if: { author_id_changed? } but I have no idea what to do with them.

I also believe the warning is related to this massive update to ActiveRecord.

Would appreciate any hand you can give with this.

UPD

This article helped alot!

Answer

Almaron picture Almaron · Jun 20, 2017

Well, got around everything by running bundle update and updating the gems and also following this article and changing attribute_changed? calls in after_ callbacks (but not in before_ callbacks and validations) and switching from attribute_was to attribute_before_last_save.