Adam D. <straightflush@…> writes:
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)
I’m not sure if these are what you’re looking for, but here are three
As long as you put your validation in your models, you get all the
validation effects (like feedback on the form telling people what they
wrong, bad fields being highlighted, etc.) for free–no need to do
pages for validation. This knocks out a lot of the things you would need
fields for one one fell swoop.
The Rails generators create CRUD scaffolding that uses two actions
transactions that you could really do in with a single action (example:
display a blank form to collect data, and “create” to accept that data
actually save it into the database). You can easily combine related
like this into a single controller by triggering one operation if the
called with HTTP GET, and the other if it’s called with HTTP POST. You
action code something like this:
Code to display blank form, or whatever
Comes here for POST–put code to save form data here
This trick basically just buys you the appearance of being on the same
(because the URL doesn’t change), when in fact you’re executing and
completely different code.
Create a second form for subsidiary data (perhaps like asking for
of an agreement, as you were asking about) and put it inside an HTML
element with inline style set to “display:none;” so that it’s invisible,
button, and instead of submitting, wire it to use one of the cool
Script.aculo.us effects in Rails to make your secondary form visible on
make it submit the original form when clicked.
#1 and #2 are pretty straightforward and standard. #3 takes a little
and can be very impressive; lots of variations on that approach are
see one example, take a look at the search box on the main
(http://script.aculo.us), and click on it’s “advanced options” link.