What is the best way to structure a multi-page form to create and edit models in a database?

前端 未结 3 607
谎友^
谎友^ 2021-01-13 17:54

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 immediat

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-13 18:12

    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.

提交回复
热议问题