I am doing a search engine for my application, it is a search form that handles two parameters: by Route and by Product, but the user can place a parameter or can place both in the search, my problem is that if the user selects one parameter, the other parameter is null and in the query it will find me where said field is null. I can not get the records unless I send both parameters, how could I solve this? here I leave my query:
@ventas = Vent.joins('left outer join detallevet on venta.Documento=detallevet.Docto')
.where('venta.IdEmpresa = ? AND venta.RutaId = ? AND detallevet.Articulo = ?',current_usuario.empresa_id, params[:search], params[:search3])
.distinct