我有2个元素:产品列表和禁用数量下拉列表。
当用户从列表中选择产品时,我想获取数量产品来更新下拉列表。
我目前的代码如下:
查看
<%= f.label "Producto" %>
<%= f.text_field :product_search, class: "form-control radius-top", value: '', placeholder: 'Buscar...', readonly: readonly %>
<%= select_tag "order_detail[product_id]", options_from_collection_for_select(@products, "id", "name"), :include_blank => 'Seleccionar producto', :class => 'form-control radius-bottom' %>
<%= f.label "Cantidad" %>
<%= select_tag "order_detail[quantity]", options_from_collection_for_select(@products, "id", "name"), :include_blank => '0', :class => 'form-control radius-bottom', disabled: true %>
控制器
def new
@order = Order.new
@customers = Customer.all.order('name ASC')
@products = Product.only_with_stock.order('name ASC')
@product_details = ProductDetail.all
end
update_quantity.js.coffee
$("#order_detail_quantity")
.empty()
.append("<%= escape_javascript(render(:partial => @product_details)) %>")
“#order_detail_quantity”是数量下拉列表,但我收到了Ajax错误。
可能有什么不好?
我真的需要帮助:(
由于
更新
Product_details list partial
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<h1 class="page-header">Inventario</h1>
<%= link_to '<button type="button" class="btn btn-success"><i class="fa fa-plus"></i> Agregar</button>'.html_safe, new_product_product_detail_path(@product) %>
<br><br>
<% if !@product.product_details.empty? %>
<div class="row">
<div class="col-lg-12">
<table class="table table-hover">
<thead>
<tr>
<th>#</th>
<th>Serial</th>
<th></th>
<th class="text-center">Comentario</th>
<th></th>
</tr>
</thead>
<tbody>
<% @product.product_details.each do |product_detail| %>
<tr>
<td><%= product_detail.id %></td>
<td><%= link_to product_detail.serial, edit_product_product_detail_path(@product, product_detail) %></td>
<td class="text-center"><span class="label label-<%= product_detail.product_status.available == true ? 'success' : 'danger' %>"><%= product_detail.product_status.name %></span></td>
<td class="text-center"><%= product_detail.comment.empty? ? '-' : product_detail.comment %></td>
<td class="text-center">
<div class="btn-group">
<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-gear"></i> <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><%= link_to 'Editar', edit_product_product_detail_path(@product, product_detail) %><li>
<li><%= link_to 'Eliminar', [@product, product_detail], method: :delete, data: { confirm: '¿Seguro que deseas eliminar el articulo ' + product_detail.serial + '?' } %></li>
</ul>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
<% else %>
<% if @product.published == true %>
<div class="alert alert-danger g-margin-b-0" role="alert">¡Este producto aun no tiene inventario y esta publicado!</div>
<% else %>
<div class="alert alert-warning g-margin-b-0" role="alert">Este producto aun no tiene inventario...</div>
<% end %>
<% end %>
</div>