从数组项中只选择一项 - Rails

时间:2017-10-31 20:07:02

标签: ruby-on-rails select

我正在使用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 %>`

0 个答案:

没有答案