Observer in Rails
Rails::Observers was introdused in Rails 3. They’re another abstracted way to watch/tarck an object life-cycle events while watching you may trigger some/any other event.
It’s a nice to have structure/solution(not recommanded) for fatty models. Observer reduce the clutter that normally comes when the model class is Over-burdened with functionality.
This Order Observer sends an email when a Order#create is done.
This Observer uses logger to log when specific callbacks as given order created/destroyed are triggered.
Available callback methods
The observer(s) can implement callback methods for each of the methods described in the Rails Callbacks module.
Observers are removed from rails core from Rails4. In Rails 4 it’s an seperate gem
To be continued note …
I am digging more into Rails::Observers. I’ll cover much more things in upcoming blog series related to Rails::Observers with an implementation of Publish–subscribe pattern
And if you get stuck… Ask Here
email me email@example.com