Search code examples
ruby-on-railspostgresqlpgransack

Getting PG::UndefinedFunction: ERROR: operator does not exist: integer ~~* integer


I am tryin to do a simple search using ransack but when i perform the search I get the following error:

ActiveRecord::StatementInvalid in GrupoFamiliars#index

PG::UndefinedFunction: ERROR:  operator does not exist: integer ~~* integer
LINE 1: ...rupo_familiars" WHERE ("grupo_familiars"."numero" ILIKE 0) L...
                                                             ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT  "grupo_familiars".* FROM "grupo_familiars" WHERE ("grupo_familiars"."numero" ILIKE 0) LIMIT 20 OFFSET 0
Here is my code

def index
  @search = GrupoFamiliar.search(params[:q])
  @grupo_familiars = @search.result.paginate(:page => params[:page], :per_page => 20)
end

<%= search_form_for @search,url: grupo_familiars_path, :class => "form-inline", :builder => SimpleForm::FormBuilder do |f| %>
  <%= f.number_field :numero_cont, :class => "form-control", placeholder: "Numero" %>
  <button type="submit" class="btn btn-default">Buscar</button>
<% end %>

Any ideas?


Solution

  • Try adding this to your model:

    class GrupoFamiliar
      # your code and stuff
      # ...
    
      private
    
      ransacker :numero do
        Arel.sql("to_char(\"#{table_name}\".\"numero\", '99999')")
      end
    end