views:

546

answers:

2

Hello

I am trying to set up a user creation wizard where the user can only go to the page that corresponds to the current step in the wizard that the user is on.

I have already sorted out the state machine functionality. The current state is stored in the DB. This is not the problem

The problem is how to redirect the user to the right page.

I first tried a before filter but that resulted in a redirect loop. The solution for this was messy.

The next thing I tried is to use redirect_to to send the request to an action that then redirects to the proper page. This resulted in a DoubleRenderError because I redirect twice. I thought redirect_to was a new http request but it seems it is not.

I am wondering now if it is possible to set up this kind of functionality in the routes directly. I will need to have access to the DB to get the current state. I have no idea how this is done or if it is even possible

Any ideas?

Thank you

+2  A: 

I am not sure if I understand your question completely.

However, the reason you got a double render error is because after a plain redirect_to ruby code continued to be executed. At some point this code attempted to render data again (hence the DoubleRenderError).

You may want to use:

redirect_to [...] and return false

This will prevent any later code from being executed and will therefore prevent a DoubleRenderError.

Good luck!

Gdeglin
A: 

I think this issue is the same as I experienced yesterday (Im on Rails 2.1), my solution can be found here on my blog, it's really simple !

R Francky