Rails的:填入表格,由此导致从一个搜索框数据 [英] Rails: Fill Table with resulting data from a search box
问题描述
因为这个问题说,我试图填写表中的数据与我谷歌,但我无法找到答案,甚至是如何做到这一点的例子,结果从轨道4的搜索框。
As the question says, i'm trying to fill data in a table with the result from a search box in rails 4. I google it but i can't find the answer or even a example about how to do this.
这是我的看法:
<% title @sale.client_name %>
<div class="hero-unit">
<CENTER><H1><%= @sale.client_name %> </H1>
<br>
<p>
Numero de Factura:<br>
<%= @sale.check_number %>
</p>
<p>
Nit del Cliente:<br>
<%= @sale.nit%>
</p>
<p>
Fecha de venta:<br>
<%= @sale.created_at %>
</p>
<p>
Total Venta:<br>
<%= @sale.price %>
</p>
<p>
<h2><Center><%= link_to_function "Ver Detalle de Venta", "$('#hide').toggle()" %> </Center></h2>
<div id="hide" style="display:none">
<table class="table table-striped">
<thead>
<tr>
<th><Center>Nombre</Center></th>
<th><Center>Codigo del SubProducto</Center></th>
<th><Center>Marca</Center></th>
<th><Center>Categoria</Center></th>
<th><Center>Precio</Center></th>
</tr>
</thead>
<tbody>
<% @sale.subproducts.each do |subproduct| %>
<tr>
<td><CENTER><%= subproduct.product.name %></CENTER></td>
<td><CENTER><%= subproduct.code %></CENTER></td>
<td><CENTER><%= subproduct.product.brand %></CENTER></td>
<td><CENTER><%= subproduct.product.category %></CENTER></td>
<td><CENTER><%= subproduct.product.sale_price %></CENTER></td>
<td><%= link_to 'Eliminar de venta', :controller => :subproducts, action => 'eliminar_subproducto_venta', :id => subproduct.id, :sale_id => @sale.id %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</p>
<% if @sale.confirmed == false %>
<p>
<h2><Center><%= link_to_function "Agregar Producto a venta", "$('#subproduct').toggle()" %></Center></h2>
<div id="subproduct" style="display:none">
<table class="table table-striped">
<thead>
<tr>
<th><Center>Nombre</Center></th>
<th><Center>Codigo del SubProducto</Center></th>
<th><Center>Marca</Center></th>
<th><Center>Categoria</Center></th>
<th><Center>Precio De Venta</Center></th>
</tr>
</thead>
<tbody>
<% @subproducts.each do |subproduct| %>
<tr>
<%if subproduct.available == true || subproduct.available == "NULL"%>
<td><CENTER><%= subproduct.product.name %></CENTER></td>
<td><CENTER><%= subproduct.code %></CENTER></td>
<td><CENTER><%= subproduct.product.brand %></CENTER></td>
<td><CENTER><%= subproduct.product.category %></CENTER></td>
<td><CENTER><%= subproduct.product.sale_price %></CENTER></td>
<td><%= link_to 'Agregar a Venta', :controller => :subproducts, :action => 'agregar_subproducto_venta', :id => subproduct.id, :sale_id => @sale.id %></td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
</div>
</p>
<%if @sale.price !=0 %>
<%= link_to 'Confirmar Venta', :controller => :sales, :action => 'confirm_sale', :identificator => @sale.id%><br>
<%end%>
<%= link_to 'Cancelar Venta', :controller => :sales, :action => 'cancel_sale', :deletor => @sale.id%><br>
<%end%><br>
<%= button_to 'Volver', sales_path, :method => :get, :class => 'btn btn-default' %><br>
</CENTER>
</div>
我想,当用户点击搜索按钮某些参数的第二个表可以刷新。
I wish the second table could be refreshed when user clicks on a search button with certain parameters.
任何人都可以帮我请?我一直在努力做到这一点的近2周,我都没有结果=(
Anyone could help me please?? i've been trying to do this for almost 2 weeks and i have no results =(
推荐答案
有很多方法可以做到这一点。最简单的是创建JS-视图 searach_table.js.erb
为您的表,该表将返回你渲染HTML表格
There are many ways to do this. The easiest is to create js-view searach_table.js.erb
for your table which will return you rendered html table
您的JS-看法:
$("#your_second_table_container").html(<%= escape_javascript(render(partial: 'search_results', locals: {subproducts: @subproducts}))%>)
和你的搜索链接:
<%= link_to 'Search', <ypur_rout_to_js_view_action>, remote: true %>
这篇关于Rails的:填入表格,由此导致从一个搜索框数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!