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.
81194a50c0f9bd95d7832a77fdf371bd?d=identicon&s=25 cool_screen_name90001 (Guest)
on 2005-11-27 11: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
3dd4b52a0946bd698b1d1635a46ea3a3?d=identicon&s=25 francois.beausoleil (Guest)
on 2005-11-28 16: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 <>:
This topic is locked and can not be replied to.