rails 中 def edit product = Productfindparamsid product_skus = productproduct_skusexists productproduct_skusfirst nil end_formhtmlerbdiv class=my-2 data-controller=nested-rondo div data-ne
如果@product_skus是一个集合(collection),可以在_form.html.erb中使用each迭代器来处理每个product_sku。修改后的代码如下:
<div class="my-2" data-controller="nested-rondo">
<div data-nested-rondo-target="fieldContain">
<% if @product_skus.present? %>
<% @product_skus.each do |product_sku| %>
<%= fields_for product_sku do |product_sku_fields| %>
<%= render "product_sku_fields", f: product_sku_fields %>
<% end %>
<% end %>
<% end %>
</div>
<div class="links">
<%= link_to_add_association "Add SKU", f, :product_skus %>
</div>
</div>
<hr class="hr-light">
<div>
<%= f.submit "保存", class: "btn btn-primary float-end" %>
</div>
这样,_form.html.erb文件将能够正确处理@product_skus集合中的每个product_sku
原文地址: https://www.cveoy.top/t/topic/icqm 著作权归作者所有。请勿转载和采集!