I'm fairly new to Rails.
What is the best way to design/structure a multi-page form in Rails? I would like the form to create a new record in the database immediately when the first page of the form is submitted, and for each subsequent page of the form to update that record in the database.
The reason I want the record created immediately after the first page is submitted is so that there can be the notion of an unfinished record that the user comes back to later to finish.
Once created, I would like to allow the user to edit any part of the model by going directly to that section.
I know enough Rails where if you guide me with the best way to structure this conceptually, I should be able to figure out the code myself.
Thank you.
Multi-page forms are an extremely popular form type and ideal for those longer forms which require multiple fields. Splitting a form into multiple pages can help provide a user-friendly and well organized layout, whilst preventing the form from feeling overwhelming to users.
The database schema is the structure of a database described in a formal language supported by the database management system (DBMS). The term "schema" refers to the organization of data as a blueprint of how the database is constructed (divided into database tables in the case of relational databases).
I have a multi-step signup process that works this way. I create the record the first time and then the other steps are edit/updates on that record. I use multiple controllers for this; it is a much cleaner approach than trying to cram all the logic into one controller action (although you could use multiple actions from the same controller and it would work just as well, but don't forget to create routes for your custom actions). This approach makes validation more difficult for the data added in steps after the first, but you can always add your own errors by calling errors.add on your model, essentially rolling your own validations. You can also write logic in your sessions controller to direct the user back to the same step in the multi-step form if they return later and have not completed it.
Ryan Bates explains this in one of his Railscasts => MultiSteps Forms
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With