Second Insert

I’m having a problem trying to come up with the best way to go about
doing something in a Rails app. Here’s the situation:

I have a form with a list of check boxes a client can choose from, but
my client also wants the user to be able to submit their own item, wich
will be saved in the table that populates the check boxes.

Does anyone have any insight into this?

Thanks a lot in advance!

Guest wrote:

I have a form with a list of check boxes a client
can choose from, but my client also wants the
user to be able to submit their own item, wich
will be saved in the table that populates the check
boxes.

I’m not sure I’m understanding exactly what you’re needing to do,
especially
with respect to exactly when the user submit’s their own item, and I’m
definitely not taking the position that this is the best way to
approach
this, but I think I had a similar situation recently so I’ll share the
approach I came up with. I thought it was butt-ugly, but it was the
best I
could come up with.

What I did was create two tables; one just to generate the form and the
second to store the results. The table I used to generate the form had
columns for each checkbox I wanted to present, and an ‘other’ column.
After
generating the scaffolding, I changed all the text fields in the form to
checkboxes. When the visitor submitted the form, I processed all the
params
and updated the second table with individual records for each item they
selected (the first table never had any records saved to it). If the
visitor checked the ‘other’ box, I displayed a second form that let them
enter that value and then that got saved as a record to the second
table.

Butt-ugly, I know :frowning:

Maybe someone will see this and educate us both! :wink:

Best regards,
Bill

Bill,

That’s sort of what I’m looking to do, but I don’t want to post back,
and make them save the changes on that individual item. I want the
second insert to happen when they save the main record. Hmmm.

Thanks for the reply.

Bill W. wrote:

Guest wrote:

I have a form with a list of check boxes a client
can choose from, but my client also wants the
user to be able to submit their own item, wich
will be saved in the table that populates the check
boxes.

I’m not sure I’m understanding exactly what you’re needing to do,
especially
with respect to exactly when the user submit’s their own item, and I’m
definitely not taking the position that this is the best way to
approach
this, but I think I had a similar situation recently so I’ll share the
approach I came up with. I thought it was butt-ugly, but it was the
best I
could come up with.

What I did was create two tables; one just to generate the form and the
second to store the results. The table I used to generate the form had
columns for each checkbox I wanted to present, and an ‘other’ column.
After
generating the scaffolding, I changed all the text fields in the form to
checkboxes. When the visitor submitted the form, I processed all the
params
and updated the second table with individual records for each item they
selected (the first table never had any records saved to it). If the
visitor checked the ‘other’ box, I displayed a second form that let them
enter that value and then that got saved as a record to the second
table.

Butt-ugly, I know :frowning:

Maybe someone will see this and educate us both! :wink:

Best regards,
Bill

Guest wrote:

That’s sort of what I’m looking to do, but I don’t want to post back,
and make them save the changes on that individual item. I want the
second insert to happen when they save the main record. Hmmm.

Gonna have to go to JS then.

Best regards,
Bill

JavaScript? Really??

Bill W. wrote:

Guest wrote:

That’s sort of what I’m looking to do, but I don’t want to post back,
and make them save the changes on that individual item. I want the
second insert to happen when they save the main record. Hmmm.

Gonna have to go to JS then.

Best regards,
Bill

Bill,

I’m definitely not make myself clear on this one. Sorry about that.

This should shed some light on my problem:

You have two tables:

Customers

CustomerSatisfactionComments

There’s a predetermined amount of satisfaction comments that we’ve
already entered, however, if the customer wants to write his own comment
in, then when they save the customer record (into customers), I want to
be able to add the custom satisfaction comment into the other table at
the same time. The problem is I guess, I don’t know how to get the value
from the form.

I’m binding the existing statisfaction comments to a list of check_box
helpers, but there’s also a custom text_field, that really isn’t tied to
the model. So when the create method is called, I’m not sure how to get
to the custom value.

Thanks Bill. :slight_smile:

Bill W. wrote:

Guest wrote:

Gonna have to go to JS then.
Maybe I’m misunderstanding what you’re trying to accomplish. If the
number
of ‘write-in’ items is not pre-set, and you don’t want to make
additional
round trips, then JS is your option for client-side processing. If
you’re
only going to give visitors a fixed number of items they can enter
themselves, then you could easily provide them with (a) text field(s) on
the
same form with the checkboxes and save all when they submit the form.

hth,
Bill

Guest wrote:

The problem is I guess, I don’t know how to
get the value from the form.

Values from forms are sent to the controller in the params hash. If
they’re
not bound to an object (i.e., you’re using FormTagHelper rather than
FormHelper) then you should be able to access the returned value with
‘controller_variable = params[:name]’.

hth,
Bill

Guest wrote:

Gonna have to go to JS then.
Maybe I’m misunderstanding what you’re trying to accomplish. If the
number
of ‘write-in’ items is not pre-set, and you don’t want to make
additional
round trips, then JS is your option for client-side processing. If
you’re
only going to give visitors a fixed number of items they can enter
themselves, then you could easily provide them with (a) text field(s) on
the
same form with the checkboxes and save all when they submit the form.

hth,
Bill