1

I am constructing a form wizard that guides the user through a form that has already been created and deployed. The model and controller should stay the same as the only thing of change is the view (guiding the user through each form field). What is the best (and easiest, if possible) way of accomplishing this task?

Even through the wizard, once the user saves their form, it gets saved to the same database via the same model and controller. From doing a bit research it seems that this is possible by obviously creating a new view, create a simple controller that extends the original controller, and routing the new controller to the new view.

Any suggestions are really appreciated. Thanks!

2 Answers 2

3

After doing some research, I figured out a couple of ways to accomplish my task:

  • A simple way is to create a wizard action within the form's controller. Have the wizard action render the wizard's view.
  • A better way is to create a wizard controller and have it subclass the form controller. Override the new action, and render the wizard view. This is the more preferred method because basic CRUD actions in Rails acquire REST for free. Thus, following this method will yield a RESTful wizard.
Sign up to request clarification or add additional context in comments.

Comments

2

You should definitely look here:

http://railscasts.com/episodes/217-multistep-forms

Otherwise, to answer shortly, you can tell any action of your controller to render ay view you want.That's what is done in the basic scaffold controller:

render :edit

6 Comments

@apneadiving Instead of subclassing the original controller (let's call it Form controller), I could simply create a FormWizard controller that subclasses ApplicationController. From there, I can specify which actions I want the FormWizard to have, with each action being able to render a specific view. Is this a good approach? How do I link the new controller/views to the Form's model, though?
@apneadiving In terms of linking the FormWizard controller and views to the Form model, I would think it's as simple as creating an instance variable in the FormWizard controller and having it pull and push data via Active Record.
That's a way to proceed but I'm unsure it's needed for two reasons: 1) generally wizards don't save the model between two pages but only at the end of the form, that's their purpose and the screencast demonstrates it with success 2) a wizard is supposed to have only one url. Otherwise you're writing a multi page form which is fine too :)
@apneadiving The video is not what I'm trying to do. My project has a two page form. My goal is to create a wizard section on the website that takes the user to the same form, but with tooltips, guiding the user through the entire form. As the user enters info into the wizard, it still saves the data into the database, as if they were filling out the original form (without the wizard/tooltips). The only thing that changes is the view (JavaScript interactivity, CSS). Does that make sense? I appreciate any feedback or any suggestions.
Ok, got it. So ok, create actions and views for each page and refactor between wizzarf and normal form if possible :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.