snippet duplicates fields x 8

Your form_for uses the @item? if so you are already looping through it’s item_item_properties, yo don’t need to loop again inside fields_for, you already have iip defined, that’s why you have everything multiplied

The solution I found was

<%= f.fields_for :item, :item_item_properties do |iip| %>

Can you please show me how you would re-write the code block using the magical iteration of @item

I’m not really sure what’s your intention and what’s the state of the @item instance. And I have to admit your namings are really confusing “item.item_item_properties” looks too repetitive, are iip and item_item_property on both loops the same class? does @item have all the item_item_properties?

I think I would do

<%= f.fields_for :item_item_properties do |iip| %>

<%= iip.label [iip.item_property.name](http://item_item_property.item_property.name/) %>
<%= iip.hidden_field :item_property_id, value: iip.item_property_id %>

<%= iip.text_field  :text_value, value: iip.text_value %>
<% end %>

But I’m not sure that’s your intention.

Also, a TD inside a DIV is not valid HTML, it will brake your template

Yes that’s what I’m doing but I get the error

ActionView::Template::Error (undefined method `item_property_id’ for #ActionView::Helpers::FormBuilder:0x000056090a542f18): 32:
33:
34: <%= f.fields_for :item_item_properties do |iip| %> 35: <%= iip.label ItemProperty.find(iip.item_property_id).name %><%= iip.hidden_field :item_property_id, value: iip.item_property_id %> <%= iip.text_field :text_value, value: iip.text_value %> 36: <% end %> 37: 38: <%= f.label :box_id %>

app/views/items/_form.html.erb:35:in `block (2 levels) in _app_views_items__form_html_erb___815224017383295294_70106289383980’

Here’s my form

<%= form_with model: @item do |f| %>

<%= f.hidden_field :item_type_id, value: @item.item_type_id %>

        <%= f.fields_for :item_item_properties do |iip| %>
            <tr><td><%= iip.label ItemProperty.find(iip.item_property_id).name %><td><%= iip.hidden_field :item_property_id, value: iip.item_property_id %> <%= iip.text_field  :text_value, value: iip.text_value %>
        <% end %>
<%= f.submit %>
<% end %>

I’m sorry, it’s “iip.object.item_proerty_id”, you have to get the object from the iip form builder