Hey Martin,
There are a couple ways you can do this. The first is to write a custom setter method for the boolean value:
class Foo < ActiveRecord::Base def bool_field=(b) self.date_field = Time.now write_attribute :bool_field, b end end
The other way is to use an Observer.
class FooObserver < ActiveRecord::Observer def before_update(foo) old_foo = Foo.find foo.id foo.date_field = Time.now if foo.bool_field != old_foo.bool_field end end
or you could put it directly in the Foo class...
class Foo < ActiveRecord::Base before_update :update_time
def update_time old_foo = Foo.find id self.date_field = Time.now if self.bool_field != old_foo.bool_field end end
Now that I've written them all out, I think the last solution would be best I would use the middle solution if I had lots of stuff to do when a record was modified.
Pat