Comparing field's old value to new value


#1

I want to expire caches if a certain field of an item changes. How can I
compare the item field’s
old value to its new value (in the create, or after_save, etc. method)?

thanks
csn


Yahoo! Mail - PC Magazine Editors’ Choice 2005
http://mail.yahoo.com


#2

Hi !

There’s after_find and after_initialize you can use to copy the
values. If you have only one or two fields, just override the field’s
setter methods:

class X < AR:Base
def attribute=(new_value)
old_value ||= read_attribute(:attribute)
write_attribute(:attribute, new_value)
end
end

Untested, and I’m not even sure write|read_attribute are the right
method names. You get the gist, though.

Bye !
François

2005/11/27, CSN removed_email_address@domain.invalid: