Skip to content

Instantly share code, notes, and snippets.

@mattlong
Forked from crivotz/rails_dirty.md
Created November 18, 2019 19:36
Show Gist options
  • Save mattlong/31e327c2c71a9902336096e175a6340a to your computer and use it in GitHub Desktop.
Save mattlong/31e327c2c71a9902336096e175a6340a to your computer and use it in GitHub Desktop.
Rails 5.2 dirty

Rails dirty

After modifying an object and after saving to the database, or within after_save:

Rails <= 5 Rails >= 5.1
attribute_changed? saved_change_to_attribute?
changed? saved_changes?
changes saved_changes
attribute_was attribute_before_last_save
previous_changes no replacement, since the behavior for it changes

After modifying an object and before saving to the database, or within before_save:

Rails <= 5 Rails >= 5.1
attribute_changed? will_save_change_to_attribute?
changed? has_changes_to_save?
changes changes_to_save
attribute_was attribute_in_database
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment