最后,我想要一个将 client_id 传递给部分的文本字段。我想异步执行此操作,以便在更新文本字段值时,shipping_products 部分会动态更改。做这个的最好方式是什么?
在 index.html.erb 中
<!-- Text Field Here-->
<div id="available_products">
<%= render "shipment_products" %>
</div>
在 _shipment_products.html.erb
<div id="shipment_products_container">
<h3>Assign Products to Ship<\h3>
<ul class="shipment_products" id="shipment_products">
<% Product.by_client(client_id).each do |product|%> <!-- TextField value passed here -->
<%= content_tag_for :li, product, :value => product.id do %>
<%= hidden_field_tag("shipment[product_ids][]", product.id) %>
<%= product.product_name %>
<% end %>
<% end %>
<\ul>
</div>
模型关系:
Models and Relationships
Shipment has_many :products :through => :shipment_products
Product has_many :shipments :through => :shipment_products
ShipmentProducts belongs_to :shipment, belongs_to :product
Product belongs_to :client
Client has_many :products
这与我最终想要的相似。