When do we need to use AASM

I am searching AASM gem to apply my demo project but I am wondering when I really need to use it and use it in what case? What is advantages and disadvantages?

So if someone has experiences on it, could you tell me know.

Best regards,

Hi,

Its a state management gem usually used in ecommerce . I’ve used them in healthcare products and social networking.

Ecommerce - Cart status : new , order_placed, :shipped, feedback_provided

Healthcare - Bed status : new, has_patient, :patiend_discharged, patient_billed

Social networking - Friendship , :friends, :request_sent, :request_accepted, :request_rejected,

Cheers

Vivek

Although I do see it work well in some cases, I also see state machine implemented badly in other cases. In particular, I find that it encourages an over-use an over-reliance on the callback hook pattern (in the context of AASM, attaching methods to specific transitions).

In smaller implementations it can work well, but as the complexity of domain logic grows it often breaks down and leads to difficult to debug code (and smelly code).

So with all things Rails, your mileage may vary. I would suggest reading up on DCI and thinking about how it might look to build an object (in the context of DCI, this is called a “context object”) that represented all the things the state transition does itself. For example, if you were going to ship a shipment, you would want to 1) change its state, 2) mark it shipped_at, 3) send an email, 4) etc, etc.

The idea behind DCI is that we consider the transition itself to be domain knowledge and give it a first-order class (although certainly not an Activerecord object) in our app. That’s the basic gist of it. It is also possible to use a state machine pattern alongside DCI or DCI-like patterns. I think the questions is, how much do you use State machine and how much do you rely on attaching hooks to your transitions.

-Jason