Late to the party -- I like Ryan's approach but was troubled by the complexity of the create() method. My modified approach has a Wizard model that saves the current_step as a db field (so it's preserved across sessions) and saves an instance before starting. From there, everything is done in the upate() method, so the controller simplifies down to:
ruby
defshow
render @wizard.current_step
enddefupdate
(params[:step] == 'back') ? @wizard.step_back : @wizard.step_forward
if@wizard.update_attributes(params[:wizard])
redirect_to wizard_path, :notice => 'update succeeded'else# the reload restores the previous (valid) step as the current step
render @wizard.reload.current_step
endend
The only other substantive change is the next / prev buttons in the views, which might look like this:
Ryan (or anyone): One question: The client is effectively doing a GET, right? And GETs are supposed to be idempotent (not change the state on the server). Do you have to do anything special to tell the server's cacheing mechanisms that a GET on the same URI twice in a row might yield different results? Or is it just luck that the &after= query parameter has that effect (since it changes continually)?
Late to the party -- I like Ryan's approach but was troubled by the complexity of the create() method. My modified approach has a Wizard model that saves the current_step as a db field (so it's preserved across sessions) and saves an instance before starting. From there, everything is done in the upate() method, so the controller simplifies down to:
The only other substantive change is the next / prev buttons in the views, which might look like this:
Ryan (or anyone): One question: The client is effectively doing a GET, right? And GETs are supposed to be idempotent (not change the state on the server). Do you have to do anything special to tell the server's cacheing mechanisms that a GET on the same URI twice in a row might yield different results? Or is it just luck that the &after= query parameter has that effect (since it changes continually)?