ruby-on-rails - 获取 PG::UndefinedFunction: ERROR: operator does not exist: integer ~~* integer

标签 ruby-on-rails postgresql pg ransack

我正在尝试使用 ransack 进行简单搜索,但是当我执行搜索时出现以下错误:

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
这是我的代码

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 %>

有什么想法吗?

最佳答案

尝试将此添加到您的模型中:

class GrupoFamiliar
  # your code and stuff
  # ...

  private

  ransacker :numero do
    Arel.sql("to_char(\"#{table_name}\".\"numero\", '99999')")
  end
end

关于ruby-on-rails - 获取 PG::UndefinedFunction: ERROR: operator does not exist: integer ~~* integer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31774989/

相关文章:

node.js - 错误 : sorry, 已经有太多客户端

ruby-on-rails - 使用 Rails 引擎共享没有命名空间的模型

ruby-on-rails - 大多数现代 Smalltalks 的集成 IDE 最让您害怕的是什么?

ruby-on-rails - 如何在生产 rails 4 中提供指纹 css 路径

ruby-on-rails - Ruby on Rails - 定义模型或表的复数名称

sql - 在 Postgresql 中授予动态数据库名称

sql - 如何使用 pgAdmin 在 postgresql 中可视化数据库表?

sql - 如何使用 golang 捕获新 postgreSQL 记录的事件

events - Postgres : Post statement (or insert) asynchronous, 非阻塞处理

PHP PostgreSQL 打开/关闭连接性能