views:

44

answers:

0

Hi folks,

I'm trying to created a set of nested (many-to-many) forms in rails 3. Everything works fine thanks to fields_for, but I need to put a title above each nested form. That title has the value of the profession_type.name field (which has a prepopulated value) in each respective nested form.

I'm having a heckuva time extracting that profession_type.name value from fields_for form objects. What I need to know is either:

a.) Is it possible to extract prepopulated values from fields_for objects, and if so how?

or

b.) How can I make a many-to-many nested form loop over only the relevant "fields_for" entry for each |specform| value, instead of all of them?

Any suggestions using either method (or alternative approaches) very much appreciated.

<% @professional.professional_specialties.each do |specform| %>
    <%= specform.profession_type.name %>

    <% f.fields_for :professional_specialties do |specialtyform| %>
        <%= specialtyform.label :profession_type %>
        <%= specialtyform.text_field :profession_type %>
        <%= specialtyform.label :qualifications %>
        <%= specialtyform.text_field :qualifications %>
        <%= specialtyform.label :license_number %>
        <%= specialtyform.text_field :license_number %>
        <%= specialtyform.label :enabled %>
        <%= specialtyform.check_box :enabled %>
    <% end %>
<% end %>