I’m looking at the callback / observer support available in AR. I’d like
to run some code after an object gets updated but only if a certain
field has changed. In postgresql triggers I’d do something like this:
IF OLD.approved_at IS NULL AND NEW.approved IS NOT NULL THEN
– bla bla some code here
END
Is there a clever way of doing this with Rails? It seems that you don’t
get a reference to the old object/row on an after_update.
I’m looking at the callback / observer support available in AR. I’d like
to run some code after an object gets updated but only if a certain
field has changed. In postgresql triggers I’d do something like this:
IF OLD.approved_at IS NULL AND NEW.approved IS NOT NULL THEN
– bla bla some code here
END
Is there a clever way of doing this with Rails? It seems that you don’t
get a reference to the old object/row on an after_update.
Jeroen
You could cache the value you are interested in when the record is
loaded, then check this against the value thats just been saved in
after_update.
I’m looking at the callback / observer support available in AR. I’d like
to run some code after an object gets updated but only if a certain
field has changed. In postgresql triggers I’d do something like this:
IF OLD.approved_at IS NULL AND NEW.approved IS NOT NULL THEN
– bla bla some code here
END
Is there a clever way of doing this with Rails? It seems that you don’t
get a reference to the old object/row on an after_update.
Jeroen
You could cache the value you are interested in when the record is
loaded, then check this against the value thats just been saved in
after_update.