I need send an email alert when the price of a product changes.
Is it possible do this with ActiveRecord::Observer
or do I need use programming logic in the edit form?
views:
28answers:
1
+2
A:
You can use Dirty Objects in order to achieve that, in this specific case, you'll have something like this in your observer.
FooMailer.deliver_alert(foo) if foo.price_changed?
According to: "Once you save a dirty object it clears out its changed state tracking and is once again considered unchanged" You should ask for the prince_changed?
before the save
operation is done.
Hope It helps you.
jpemberthy
2010-07-21 15:40:16
@jpemberthy My mystake in grammar. I want to send the alert when the price changes, not "only" the price. What I tried to meant was I don't want alert when other attributes change. Sorry. I edited my question. Can you update your answer?
Erik Escobedo
2010-07-21 15:46:58
Updated, now It uses a dynamic method (cool stuff) :).
jpemberthy
2010-07-21 15:56:33