Forum: Ruby on Rails multi step forms

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F15fdc7cb2e911b3808837f2be244add?d=identicon&s=25 straightflush (Guest)
on 2005-11-17 19:09
(Received via mailing list)
sorry for re-posting this, my first one didnt seem to get through.

Is there an elegant way to handle forms in a controller/view that
need to go thru multiple steps. Like 1) validating content, and 2)
adding a step like first accepting an Agreement?

 Just wondering if rails had a way to handle this without me having
to post to the controller twice and render a view based on a hidden
form value (input type=hidden name=step value=2 kind of thing)

thanks
adam
Fdc7ff1d176325ed86c81c7c4584f0ad?d=identicon&s=25 dmitry (Guest)
on 2005-11-17 21:20
(Received via mailing list)
On Friday 18 November 2005 01:08, Adam Denenberg wrote:
> sorry for re-posting this, my first one didnt seem to get through.
>
> Is there an elegant way to handle forms in a controller/view that
> need to go thru multiple steps. Like 1) validating content, and 2)
> adding a step like first accepting an Agreement?
>
>  Just wondering if rails had a way to handle this without me having
> to post to the controller twice and render a view based on a hidden
> form value (input type=hidden name=step value=2 kind of thing)
No, AFAIK Rails doesn't handle it for you. You need to develop your
own solution for the problem.

My guess would be to create an inermediate object, something like
ModelConstructor that will encapsulate models you're creating from
the forms and handle their validations.

Then you can store this object in session, without saving it to the DB
until the final step is over. You can handle validation in middle
steps by calling Rails validate method inside Constructor object and
by stripping off all not-yet-filled fields from errors hash, to check
if model is correct for the current step.

Hope that helps.
This topic is locked and can not be replied to.