How to create a multi step Registration model

Hi, am working on a side project where I have a User model and want to have multiple models associated with this please see my use case below.

  • 3 models particularly dependent on a user model(devise)
  1. personal profile
  2. family details
  3. partner preference
  • once the user is authenticated and confirmed(devise) he/she has to go to “personal profile” model as the next step

  • the next step would be family details followed by partner preference

  • This wizard process happens only first time logging.

  • I need all these models saperatly

Hi there,

If I understand you correctly, it looks like you want wizard (or multi-step) form during the user registration process that populates the user data into multiple models/database tables.

I think that the easiest way I would build this multi-step registration form is in two steps.

1. Make a form to store all your data properly
You’re going to want to make a larger single form that can accept all the data you’re asking the user for and store it properly in the database across all 3 models.

The default rails way to make a complex form like this is through nesting your form and adding accepts_nested_attributes_for in your appropriate models. More often than not, this method leads to a lot of unnecessary complexity and non-descriptive errors.

I would (and I think the thoughtbot crew would too) recommend making a “Form Object” instead for a very clean way to store all the data you want from your user.

The weekly iteration video linked above will definitely help you make that form, but if you need other references I recommend “ActiveModel Form Objects” from the thoughtbot blog or “#416 Form Objects” from RailsCasts.

2. Split the form up into a wizard
Once you have a single Form Object that can collect and store the user’s information properly, the next step is to break this form up into a multi-step form, or a “wizard”.

There is a popular gem named wicked which helps developers break up their large forms into wizards. The README on github has many links to help you get started.

You can make a wizard yourself if you’re up to the challenge, but I think using wicked will be your fastest option.

Let me know if this helps,
– Pete

1 Like

Thanks a lot, Pete. I had already started working with the wicked gem, but wanted to be sure, is this the right way or not.

How can we make Api with multi step registration? do I have to use wicked?

Follow this - Multi-step registration form