【发布时间】:2012-06-24 22:04:36
【问题描述】:
最后,我想要一个将 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
这和我最终想要的差不多。
【问题讨论】:
标签: ruby-on-rails ajax jquery ruby-on-rails-3.1