News for hackers. Stuff that matters.
Re:Why Developers Never Use State Machines by relix on Thursday September 01, 2011 @11:22AM (#2950364)
I discovered how state machines can be practical when checking the source code of Spree, the rails e-commerce engine. The checkout-process is a state machine.

I'd highly recommend using state machines for multi-step forms. It feels very natural and keeps you sane, I believe it should be a best practice.

Re:Why Developers Never Use State Machines by IProgrammer on Thursday September 01, 2011 @02:30PM (#2951183)
>I'd highly recommend using state machines for multi-step forms. It feels very natural and keeps you sane, I believe it should be a best practice.

That's interesting. Can you elaborate on it, maybe with an example?

Re:Why Developers Never Use State Machines by relix on Friday September 02, 2011 @08:04AM (#2953787)
Basically each step in your form is a state in the state machine. When a user submits one step, you move the state machine to the next state. You can add conditionals for when to skip a step, and you can specify validations for each step that need to be run before a state-change (e.g. credit card needs to check out before moving from the credit card step to the confirm step).

You can check out Spree's state machine for the checkout process here: https://github.com/spree/spree/blob/master/core/app/models/o... (starts at line 83). Notice that the Order model is the state machine.