Forum: Ruby on Rails @#$%ing forms using collection_select

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7f81419ef29a86176e43845d955085bb?d=identicon&s=25 Frank Kany (frank_programmer)
on 2009-03-03 17:47
Attachment: form.txt (2 KB)
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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-03 17:55
(Received via mailing list)
On 3 Mar 2009, at 16:47, Frank Kany 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
E4681a514c48f1c6de50747be9d96d3f?d=identicon&s=25 Sébastien Dabet (fiddler)
on 2009-03-03 18:00
Frank Kany 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 ?
7f81419ef29a86176e43845d955085bb?d=identicon&s=25 Frank Kany (frank_programmer)
on 2009-03-03 19:13
Attachment: form.txt (1 KB)
Frederick Cheung wrote:
> On 3 Mar 2009, at 16:47, Frank Kany 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.
This topic is locked and can not be replied to.