I have a nested attribute form with the following and I'm just learning how to use nested attributes. One of the problems I am facing is that the values โโof child_index are not incremented. I get 3 fields based on the assembly in the controller, but they all have 0 or 1 depending on what number is set to.
Any ideas on how to make this increase?
# in controller: 3.times {@item.assets.build} <% number = 1 %> <div id='files'> <%= f.fields_for :assets, :child_index => number do |asset| %> <p> number:<%= number %><br /> <%=asset.label :asset, "File ##{number += 1}" %> <%= asset.file_field :asset %> </p> <% end %> </div> <%= f.submit %>
edit: so all of them in html will have the form:
item[assets_attributes][0][asset]
not desired:
menu_item[assets_attributes][0][asset] menu_item[assets_attributes][1][asset] menu_item[assets_attributes][2][asset]
edit # 2: therefore, looking at the source code, I see the following and wonder if the rails should do automatic pumping and maybe this does not happen;
<input id="item_assets_attributes_0_asset" name="item[assets_attributes][0][asset]" type="file" /> <input id="item_assets_attributes_0_id" name="item[assets_attributes][0][id]" type="hidden" value="1" />
source share