Forum: Ruby on Rails dynamic select box form field parameter not being submitted

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
74a56286718bc003d6c7438f7efa1e3a?d=identicon&s=25 Navjeet Chabbewal (jeet)
on 2007-03-24 20:25
(Received via mailing list)
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

Seems like I can't use 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.
74a56286718bc003d6c7438f7efa1e3a?d=identicon&s=25 Navjeet Chabbewal (jeet)
on 2007-03-24 21:11
(Received via mailing list)
I fixed my problem.

The problem was that the form_for helper was after the html <table>
tag and before the <tr> 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 <table> ta everything was
fine. Hope somebody else can benefit from this.
This topic is locked and can not be replied to.