Dirty field checking
Now that we’ve upgraded to rails 2.1, I have a handy new activerecord tool called Dirty that tracks unsaved attribute changes.
Rather than the code below:
newscoretype = 1
oldscoretype = score.scoretype_id
if oldscoretype == newscoretype...
I can instead write:
if score.scoretype_id_changed?...
I still have easy access to the old value using _was
oldscoretype = score.scoretype_id_was
There are also methods that query the dirty state of the whole model, e.g. score.changed?
Love it.



