Skip to content

Instantly share code, notes, and snippets.

@n00ge
Last active October 11, 2015 17:17
Show Gist options
  • Save n00ge/3892456 to your computer and use it in GitHub Desktop.
Save n00ge/3892456 to your computer and use it in GitHub Desktop.
Rails attribute changed?
my_model = MyModel.find(:first)
my_model.changed? # it will return false
# You can Track changes to attributes with my_model.name_changed? accessor
my_model.name # returns "Name"
my_model.name = "New Name"
my_model.name_changed? # returns true
# Access previous value with name_was accessor
my_model.name_was # "Name"
# You can also see both the previous and the current values, using name_change
my_model.name_change #=> ["Name", "New Name"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment