Forum: Ruby on Rails Comparing field's old value to new value

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
cool_screen_name90001 (Guest)
on 2005-11-27 12:39
(Received via mailing list)
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)?


Yahoo! Mail - PC Magazine Editors' Choice 2005
francois.beausoleil (Guest)
on 2005-11-28 17:42
(Received via mailing list)
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)

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

Bye !

2005/11/27, CSN <removed_email_address@domain.invalid>:
This topic is locked and can not be replied to.