Skip to content

Instantly share code, notes, and snippets.

@crivotz
Last active November 15, 2021 11:09
Show Gist options
  • Save crivotz/82e3801e296fcad27e687ceb0fdb64f3 to your computer and use it in GitHub Desktop.
Save crivotz/82e3801e296fcad27e687ceb0fdb64f3 to your computer and use it in GitHub Desktop.
Rails dirty prameters

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