Rails 3.2 Ajax Update Div when Text Field Populated

Posted by ctilley79 on Stack Overflow See other posts from Stack Overflow or by ctilley79
Published on 2012-06-22T15:12:34Z Indexed on 2012/06/24 15:16 UTC
Read the original article Hit count: 451

In the end I would like a text field that passes a client_id to the partial. I would like to do this asynchronously so the shipment_products partial would dynamically change when the textfield value was updated. What is the best way to do this?

In index.html.erb

<!-- Text Field Here-->
<div id="available_products">
  <%= render "shipment_products" %>
</div>

In _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>

This is similar to what I want in the end. enter image description here

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about ruby-on-rails