views:

94

answers:

2

What are best-practices (or usual-practices) when it comes to adding more steps in a process in Rails?

For example, I am working with the Spree e-commerce Rails platform and I would like to add a multi-step form people should fill out when trying to "Add to Cart" a Product.

The current spree implementation of adding a product to the cart is basically:

ProductsController#show -> OrdersController#edit

That adds the product to the cart, and leaves you at the cart.

So I'm wondering, in order to most-minimally change the core code in spree, how do I make it so the process is more like this:

ProductsController#show -> SurveysController#show -> (survey stuff...) -> OrdersController#edit

What I'm thinking to do is:

  • modify the "products/show.html.erb" so it goes to surveys_controller.rb. Also modify products_controller.rb to put session[:redirect_to] = order_checkout_path, which I can handle in the SurveysController.
  • or just make those extra things popups, and when I get to the last one, have it call the original method.

What's wrong with that? What is a better approach? This is a question about, more generally, how people go about architecting multistep processes without modifying core code. Not a wizard, just adding extra things in the middle of other things.

Thanks for your help, Lance

A: 

It's not a very standard flow in a RESTful web app, so whatever you do will have to be someone hackish, since Rails provides no easy way.

The session variable seems fine to me. Short and simple. You may want to make your key something more descriptive, though, so that you don't see future conflicts.

Matchu
+1  A: 

You might check out restful_workflow:

This plugin provides interview-style workflow in a controller, similar to TurboTax, but without the need to save models to the database immediately. All data is stored in the session unless overridden.

wesgarrison