Dynamic select box form field parameter not being submitted

I am trying to create a dynamic select box (contact_preferences
options list) based on a selection made in another select box (user
contact_preference_opt_in). I am using form_for to build the form that
has user contact_preference_opt_in select box. The contact_preferences
options list select box is in a partial. I use observe_field on first
select box which calls an action (passes the selected value to it) to
build an array used to populate the second drop down. All this works
well but when I submit the form the second select box selection is not
sent in the form (params).

Currently I am using the select helper (e.g.
select(:user, :contact_preference, @preferences) where @preferences
array is populated in the action. Can I use this inside form_for
rather than f.select?

Seems like I can’t use f.select way of populating the select box in
the partial as it does not know about the context of variable f when
the partial is called from the action.

This should be common problem and I must be doing something wrong here.

I fixed my problem.

The problem was that the form_for helper was after the html


tag and before the tag. Because of that the form element for the
second dropdown was somehow not being considered part of the form.
Once I moved the form_for helper before the
ta everything was
fine. Hope somebody else can benefit from this.