私は自分のビューでクエリの結果を表示していますが、このクエリは2つの異なるテーブルを使用しています。データ検索ではransack gemを使用して検索しますが、形式: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、[clientses] .IdCli AS Cliente") – luis31