Instance variables best solution for wizard type

Hello All,

This is my first post so if you could not crucify me publicly I would appreciate.

I beleive I have a simple question but do not manage to find the answer.

Basically I want to create a wizard type of system where the customer enters some info on the first page then goes to step 2, some more info, then step 3 and finishes. Each steps represent an action in the same controller. I have declared an instance variable (@step1) in the first step and needs it in the last finishing step.

If I try to use that variable, it gives me a null pointer exception. The lifespan of a instance variable is between the controller and the view and dies thereafter? Can it be for the entire lifespan of the controller?

More concrete exemple:

--- step 1 --- name , address ect... + internal info set within the action --- step 2 --- depends on info entered in step 1 + favorite cat -- step 3 --- depends on step2 + favorite dog -- step 4 -- finishes -> saves into the db === > name, address, internal info set by action "step1" + favorite cat + favorite dog

How can in action "step4" access the data set internaly un "step1" plus the data entered by the client in the further 3 actions?

Hope it is clear engough. I heard of acts_as_wizard but beleive this situation do not require a plugin - good for my learning curve as well...

Cherio, Carl

Hello Again,

Should I use accessors by any chance? Any exemple would be much appreciated.

Carl

Hi --

Hello All,

This is my first post so if you could not crucify me publicly I would appreciate.

I beleive I have a simple question but do not manage to find the answer.

Basically I want to create a wizard type of system where the customer enters some info on the first page then goes to step 2, some more info, then step 3 and finishes. Each steps represent an action in the same controller. I have declared an instance variable (@step1) in the first step and needs it in the last finishing step.

If I try to use that variable, it gives me a null pointer exception. The lifespan of a instance variable is between the controller and the view and dies thereafter? Can it be for the entire lifespan of the controller?

It is :slight_smile: The thing is, though, the lifespan of the controller is only one action.

The controller is actually an instance of your controller class. When you run an action -- say, 'login' for a user controller -- what happens is (in simplified form):

   c = UserController.new # create an instance of the controller    c.login # call a method ("action") on that instance

On the next action, a new instance of your controller is created. And so on.

Every object has its own instance variables; therefore, each controller instance has its own instance variables.

Have you looked at the special 'session' hash? You can use it to store data between actions.

David