1. 2

You may come to the point, where you to have certain elements that are bound to your model but don’t belong either there nor in the controller. This article will explain how you can use Observers in your Padrino application.

  1.  

  2. 2

    You may come to the point, where you to have certain elements that are bound to your model but don’t belong either there nor in the controller.

    I don’t follow why they don’t belong in the model. These are behaviors that change the state of the model - it’s deeply coupled to attributes provided by the model. I am not convinced this is an example of good design, though it does cover the mechanics of how you can use that feature.

    1. 1

      It is worth noting that ActiveRecord::Observers was removed from Rails 4 in favor of using more explicit methods to invoke behavior.

      The current trend is to use a service object to encapsulate work that doesn’t cleanly fit into a model, although there are undoubtedly other approaches as well.