我正在使用fields_for并选择方法,但此代码没有可用性。使用JSON或js fielter`
可能会更好<%=form_for @order do |f| %>
<%@categories.each do |category| %>
<% if category.produc
ts.any? %>
<div class="text-center">
<h2><%= category.name%></h2>
</div>
<%= f.fields_for :order_items, @order.order_items.build do |oi| %>
<div>
Product: <%= oi.select :product_id, category.products.pluck(:title, :id) %>
Quantity: <%= oi.number_field :quantity, min: 1, value: 1 %>
</div>
<% end %>
<% end %>
<% end %>
<%= f.submit "Create order" %>
<% end %>`