# @#$%ing forms using collection\_select

**URL:** <https://www.ruby-forum.com/t/ing-forms-using-collection-select/161905>\
**Category:** Rails\
**Created:** [March 3, 2009, 5:47pm UTC](https://www.ruby-forum.com/t/ing-forms-using-collection-select/161905 "2009-03-03T17:47:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![frank\_programmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/958977/32.png) [@frank\_programmer](https://www.ruby-forum.com/u/frank_programmer)\
**Post date:** [March 3, 2009, 5:47pm UTC](https://www.ruby-forum.com/t/ing-forms-using-collection-select/161905/1 "2009-03-03T17:47:08Z")

</div>

Good morning,

I have a form with 5 fields. When I click “Save”, 3 of the 5 fields  
save to the database and the other 2 are saved as NULL.

The form code is attached.

The 2 fields that will not save are using collection\_select. On the web  
page I can click on each of the drop down boxes and select an item, but  
for some reason they will not save to the database fields.

Thank you,

Frank

---

<div class="post-metadata">

**Author:** ![frank\_programmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/958977/32.png) [@frank\_programmer](https://www.ruby-forum.com/u/frank_programmer)\
**Post date:** [March 3, 2009, 5:55pm UTC](https://www.ruby-forum.com/t/ing-forms-using-collection-select/161905/2 "2009-03-03T17:55:36Z")

</div>

On 3 Mar 2009, at 16:47, Frank K. wrote:

> page I can click on each of the drop down boxes and select an item,  
> but  
> for some reason they will not save to the database fields.

Hard to tell without the matching controller code but I’m guessing  
that your controller code is expecting the collection\_select  
parameters to be in the same place as other ones (ie inside  
params[:time\_subtype], assuming that’s the name of your model) but it  
won’t be because you’re using a raw collection\_select rather than  
form.collection\_select.

Fred

---

<div class="post-metadata">

**Author:** ![frank\_programmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/958977/32.png) [@frank\_programmer](https://www.ruby-forum.com/u/frank_programmer)\
**Post date:** [March 3, 2009, 6:00pm UTC](https://www.ruby-forum.com/t/ing-forms-using-collection-select/161905/3 "2009-03-03T18:00:24Z")

</div>

Frank K. wrote:

> Good morning,
> 
> I have a form with 5 fields. When I click “Save”, 3 of the 5 fields  
> save to the database and the other 2 are saved as NULL.
> 
> The form code is attached.
> 
> The 2 fields that will not save are using collection\_select. On the web  
> page I can click on each of the drop down boxes and select an item, but  
> for some reason they will not save to the database fields.
> 
> Thank you,
> 
> Frank

I think that :name, :comment, :active\_flag values are stored in the  
params[:time\_subtype] array because text\_field, text\_area and check\_box  
are called on the form object.  
However your collection\_select calls do not refer to the form, so  
they’re not stored in params[:time\_subtype], and if you update your  
object with params[:time\_subtype] as parameter the :entity\_id,  
:time\_type\_id are not found.  
With your code these values are accessible in  
params[:facility][:entity\_id] and parms[:time\_type][:id]. What  
attributes do these two form elements refer to ?

---

<div class="post-metadata">

**Author:** ![frank\_programmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/958977/32.png) [@frank\_programmer](https://www.ruby-forum.com/u/frank_programmer)\
**Post date:** [March 3, 2009, 7:13pm UTC](https://www.ruby-forum.com/t/ing-forms-using-collection-select/161905/4 "2009-03-03T19:13:04Z")

</div>

Frederick C. wrote:

> On 3 Mar 2009, at 16:47, Frank K. wrote:
> 
> > page I can click on each of the drop down boxes and select an item,  
> > but  
> > for some reason they will not save to the database fields.
> 
> Hard to tell without the matching controller code but I’m guessing  
> that your controller code is expecting the collection\_select  
> parameters to be in the same place as other ones (ie inside  
> params[:time\_subtype], assuming that’s the name of your model) but it  
> won’t be because you’re using a raw collection\_select rather than  
> form.collection\_select.
> 
> Fred

Ahhhh…the form.collection\_select pointed me in the right direction.  
I’ve attached my changes. Thank you Fred & SÃ©bastien for your replys.
