Detecting attribute changes in callbacks

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?

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

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
looking in the docs it appears that they are. If I am mistaken please
me know. But otherwise, sorry for talking to myself on the mailing list

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs