how to create wizard forms in ruby on rails

后端 未结 5 1991
臣服心动
臣服心动 2020-12-08 16:10

I\'m trying to understand the best options for pulling off a wizard form in ruby on rails. Ideally I\'d like to have it so the application signup has a back and next button

相关标签:
5条回答
  • 2020-12-08 16:38

    There are a couple of plugins that provide wizzard construction facilitation in rails.
    Acts as Wizard and Wizardly seem the most popular.
    The main idea is to:
    * create a model in the first step
    * then edit it on subsequent steps,
    * applying partial validation on each step and
    * having the model implement some sort of state machine.

    0 讨论(0)
  • 2020-12-08 16:38

    Wicked looks promising for rails 3:

    https://github.com/schneems/wicked

    0 讨论(0)
  • 2020-12-08 16:44

    Have a look at wicked, explained in this rails cast: http://railscasts.com/episodes/346-wizard-forms-with-wicked?autoplay=true

    0 讨论(0)
  • 2020-12-08 16:50

    An alternative approach, for simpler multi step forms especially, is to simply show-hide parts of a single form depending on the step, this way you don't hit the database on every step but rather let the user build up his object until he's ready with a valid instance.

    Such an approach strongly favors using a form class instead of working with the model directly (http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/) and you need to tweak error message rendering a bit.

    Pros: only one db hit, no hassle with persisting invalid instances (not null columns, before_save sanity checks for messed up attributes), no callback hell

    Cons: more html sent to user, error message tweaks, requires a well built form class to be elegant and really useful

    0 讨论(0)
  • 2020-12-08 16:59

    You should watch this rails cast episode on multi step forms:

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

    Be prepared to rewind and watch again. He's very quick!

    0 讨论(0)
提交回复
热议问题