Set Up The Parent Table
The parent table is the table that carries the user through whatever multi step process they’re completing. Whenever a user starts a new submission, our process is as follows:- Create a new record in the parent table.
- Generate a shortcode for that record.
- Pass this shortcode from step to step throughout the process.
Order
model. First we’ll add a new column to the table
Side Note: Conditional Validations
ActiveRecord validations are great, but usually they’re applied universally, not conditionally. For this flow, we want to have a way to switch between different “sets” of validations, depending on what step the user is on.Step One: Creating the record
For the first step of the flow, the user will simply click on a link and get taken to step one of a form.Building The Form
Now lets add the route that shows the first step. We’re going to use:match
here for reasons we’ll explore in a few minutes.
Form submission and showing validation errors.
The view above will display the form to the user and let them fill it in. But we also want to cover the scenario where the user has submitted the form but some of the validations haven’t passed.- The user has landed on the first step of the form but not submitted it yet. Just show them the form.
- The user has submitted the form and there are validation errors. Show them the form as well as the validation errors.
- The user has submitted the form and the validation has passed. Redirect them to the next step
Nested Relationships
Use a normal link to add an itemfields_for
form helper