Last active
October 11, 2015 17:17
-
-
Save n00ge/3892456 to your computer and use it in GitHub Desktop.
Rails attribute changed?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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