# Second Insert

**URL:** <https://www.ruby-forum.com/t/second-insert/95461>\
**Category:** Rails\
**Created:** [June 1, 2006, 11:08pm UTC](https://www.ruby-forum.com/t/second-insert/95461 "2006-06-01T23:08:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [June 1, 2006, 11:08pm UTC](https://www.ruby-forum.com/t/second-insert/95461/1 "2006-06-01T23:08:07Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [June 2, 2006, 12:13am UTC](https://www.ruby-forum.com/t/second-insert/95461/2 "2006-06-02T00:13:31Z")

</div>

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 ☹

Maybe someone will see this and educate us both! 😉

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [June 2, 2006, 5:01am UTC](https://www.ruby-forum.com/t/second-insert/95461/3 "2006-06-02T05:01:35Z")

</div>

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 ☹
> 
> Maybe someone will see this and educate us both! 😉
> 
> Best regards,  
> Bill

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [June 2, 2006, 5:54am UTC](https://www.ruby-forum.com/t/second-insert/95461/4 "2006-06-02T05:54:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [June 2, 2006, 6:01am UTC](https://www.ruby-forum.com/t/second-insert/95461/5 "2006-06-02T06:01:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [June 2, 2006, 4:04pm UTC](https://www.ruby-forum.com/t/second-insert/95461/6 "2006-06-02T16:04:09Z")

</div>

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. 🙂

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

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [June 2, 2006, 4:49pm UTC](https://www.ruby-forum.com/t/second-insert/95461/7 "2006-06-02T16:49:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [June 2, 2006, 2:31pm UTC](https://www.ruby-forum.com/t/second-insert/95461/8 "2006-06-02T14:31:53Z")

</div>

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
