Detecting attribute changes in callbacks


#1

Hey all,
What is the best/easiest way to detect if a certain AR model
attrirbute has changed in a callback? For example, I have a date
field in my model that needs to be updated when a certain attribute
has been changed. What is the best way to do this in a call back?
Thanks,
Ben


#2

After looking at some previous threads it looks like th best way to do
with
is to overwrite the attribute writer in the model like so:
def name=(val)
@old_name = (val == name) ? nil : name
super val
end

And then just checking the @old_val in the callback… I thought that
these accessors were not always used in all the update methods, but
after
looking in the docs it appears that they are. If I am mistaken please
let
me know. But otherwise, sorry for talking to myself on the mailing list
:slight_smile:
-Ben