【发布时间】:2017-04-24 18:12:29
【问题描述】:
我在视图中显示查询的结果,该查询使用两个不同的表,对于数据搜索,我使用 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 %>
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 ransack