Anyone have any experience implementing a sequential multistep
workflow in Rails that touches a number of models?
I'm building a multi-step purchase process for an insurance product.
The nature of the process means that I have number of models, roughly
one per form. At the moment I've implemented each step as an action
and am using redirect_to to navigate between steps. It works well,
but I can't help thinking that the redirect is wasteful, what with it
requiring an additional round trip to the server before the user sees
the next step.
I've toyed around with using 'render :action => "my_next_step"'
instead but it confuses my views which expect instance variables to be
set up for their respective steps.
Anyone got a better idea?
Thanks,
Regards,
Tony.
You could set up a model which details out the next step in the DB, i.e. the specific controller, action to present next. On each step being complete it would simply refer to the proceeding step in the model. That way you could present the full steps to the user, not just the next one but also the proceeding one as well.
On Fri, Apr 11, 2008 at 3:59 PM, Tony Byrne <tony...@gmail.com> wrote:
Hi Folks,
Anyone have any experience implementing a sequential multistep
workflow in Rails that touches a number of models?
I'm building a multi-step purchase process for an insurance product.
The nature of the process means that I have number of models, roughly
one per form. At the moment I've implemented each step as an action
and am using redirect_to to navigate between steps. It works well,
but I can't help thinking that the redirect is wasteful, what with it
requiring an additional round trip to the server before the user sees
the next step.
I've toyed around with using 'render :action => "my_next_step"'
instead but it confuses my views which expect instance variables to be
set up for their respective steps.
Anyone got a better idea?
Thanks,
Regards,
Tony.
>
> I have a similar problem to solve in one of my applications. I have a
> model which represents the purchase process, it stores the IDs of the
> objects chosen in the various steps. This model has a state machine, I
> used acts_as_state_machine, and it knows the next step it needs to
> take based on the state machine specification.
>
> The state of the state machine corresponds to the name of the action
> within the purchase controller.
>
> The advantage of doing it this way is that if a customer gets
> interrupted, or if an invalid choice is somehow made in one of the
> steps, the state machine can always be trusted to present the next
> question required. It's also flexible enough to, say, skip a step
> which might be irrelevant based on a previous choice.
That sounds like it might be what I need. Any pointers to sample
code? My Googling only reveals code snippets for the model, but
I don't understand how to make use of a FSM equipped model
in the controller.
Thanks!
Regards,
Tony.
I owe you a debt of gratitude for taking the time to detail your
solution (especially since you did it on your lunch break!).
I'll have a look at the code and see whether inspiration strikes.
Thanks again!
Regards,
Tony.