0
我在我的视图中显示查询的结果,此查询使用两个不同的表和数据搜索我使用ransack gem执行搜索,但它显示我在搜索中出现以下错误形式:使用搜索宝石搜索
ActionView::Template::Error (undefined method `Producto_cont' for Ransack::Search<class: Stoc, base: Grouping <combinator: and>>:Ransack::Search):
字段“PRODUCTO”我从所谓的“PRODUCTOS”另一个表中获取它,它是查询的结果,那只能说明我与另外一个,我等领域的错误在查询中,而不是与我所调用的方法相同,即“Stoc”
这是我的方法控制器:
@search = Stoc.productos_de_un_stock(params).search(search_params)
@search.sorts = 'Stock desc' if @search.sorts.empty?
@stock = @search.result().page(params[:stock]).per(15)
这是我的查询:
def self.productos_de_un_stock(params)
query = select("[stock].IdStock, [stock].Stock, [productos].Clave AS Clave_producto, [productos].Producto, [productosxpzas].PzaXCja AS PzaXCja")
.joins('inner join productos ON stock.Articulo = productos.Clave inner join productosxpzas ON productos.Clave = productosxpzas.Producto')
.where('stock.Ruta = ? AND stock.IdEmpresa = ?', (params[:search]), (params[:search6]))
query
end
这是我的搜索形式:
<%= search_form_for @search, :remote=>"true", url: busqueda_stock_path, :method => :get do |f| %>
<div class="rwd">
<table class="table table-striped table-bordered table-condensed table-hover rwd_auto">
<thead>
<tr>
<th class="component_name_header_col"><%= sort_link @search, :Articulo, "Clave","stoc", {}, { :remote => true, :method => :get } %></th>
<th class="action_col"><%= t("basic.action") %></th>
</tr>
<tr>
<th><%= f.text_field :Articulo_cont, class:"campo" %></th>
<%= f.search_field :Producto_cont %>
<input id="search" type="hidden" value="<%=params[:search] %>" name="search"/>
<input id="search6" type="hidden" value="<%=params[:search6] %>" name="search6"/>
<th><%= f.submit "Buscar" %></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<% end %>
谢谢你的回应,非常感谢你的例子,我理解你的观点,但如果我想从查询中获取数据,请选择字段被重命名为“AS” ?例如,从这部分:: select(“[rutas] .Ruta AS ruta,[clientes] .IdCli AS Cliente”) – luis31