I could use some suggestions on how to proceed from where I am to where
I want to go.
I’m working on an app that collects info from the visitor and saves it
to a file. The file can later be read in for update. To collect the
info, the app presents a form with a set of checkboxes. The state of
the checkboxes at initial presentation is controlled by a summary record
that is created / populated when the file is read in for updating. The
record contains fields for each of the checkboxes with the value = ‘y’
or ‘n’. In addition to a set of ‘standard’ selections, the form also
has a checkbox labeled ‘Other’.
Currently, when the form is submitted, individual records are created
for each checked checkbox for the standard selections. If the ‘Other’
checkbox is checked, after records are created for the ‘standard’ items,
I render a second page with a form that allows them to enter one or more
other items. Individual records for those items are created via RJS as
the items are entered.
I’d like to allow the addition of the ‘Other’ items on the same page as
the standard checkbox selections. If the visitor checks the ‘Other’
checkbox, I want to replace the checkbox with the partial that’s
currently being rendered on the second page. I can do that by putting
the ‘Other’ checkbox in a
Unfortunately RoR doesn’t support forms within forms. Clicking the
‘Submit’ button on the sub-form submits the entire form. So that
doesn’t work for me.
I’m considering eliminating the top level form and just using a
‘button_to’ to pass the entered info from the view back to the
Pro: The ‘Other’ form processing works fine
Con: Since they’re not contained within a form anymore, the checkboxes
aren’t serialized and passed to the controller via the params hash.
I believe I can use ‘checkbox_tag’ instead of ‘checkbox’ to get the
values back to the controller, but that leaves me with the chore of
initializing them for presentation from the values in the summary
record. Overall, this path feels non-Railish.
Any suggestions would be greatly appreciated.