gpt4 book ai didi

ruby-on-rails - 在 :string not working on Active Admin (Rails 3. 2/postgresql 上过滤)

转载 作者:数据小太阳 更新时间:2023-10-29 08:12:25 26 4
gpt4 key购买 nike

我在 Daily Deal 应用程序上使用 Active Admin。

我遇到了一个非常具体的问题:当我在定义为 filter :as =>:string 的字段上的过滤器侧边栏上启动搜索时,我收到此错误:

enter image description here

ActiveRecord::StatementInvalid at /admin/users
PG::UndefinedFunction: ERROR: operator does not exist: character varying >> unknown
LINE 1: ...ECT COUNT(*) FROM "users" WHERE ("users"."email" >> 'math')
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT COUNT(*) FROM "users" WHERE ("users"."email" >> 'math')

奇怪的是,如果我选择“包含”而不是“等于”或“开始于”或“结束于”,它会完美地工作。我只对“包含”有疑问。

这就像 postgresql 不理解命令 Active Admin filter on string with 'contain' 要求他做的那样。

我尝试了很多我的模型,它发生在我所有的模型中。

这是事件管理页面:

ActiveAdmin.register People do
filter :name, :as => :string
end

这是我的 gemfile

gem 'activeadmin',            github: 'gregbell/active_admin' # added github because of 
gem 'pg'

这是我在本地得到的完整信息:

Started GET "/admin/users?utf8=%E2%9C%93&q%5Bemail_contains%5D=math&commit=Filter&order=id_desc" for 127.0.0.1 at 2014-03-01 17:45:42 +0100
Processing by Admin::UsersController#index as HTML
Parameters: {"utf8"=>"✓", "q"=>{"email_contains"=>"math"}, "commit"=>"Filter", "order"=>"id_desc"}
AdminUser Load (1.4ms) SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = 1 ORDER BY "admin_users"."id" ASC LIMIT 1
(2.3ms) SELECT COUNT(*) FROM "users" WHERE ("users"."email" >> 'math')
**PG::UndefinedFunction: ERROR: operator does not exist: character varying >> unknown
LINE 1: ...ECT COUNT(*) FROM "users" WHERE ("users"."email" >> 'math')
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.**
: SELECT COUNT(*) FROM "users" WHERE ("users"."email" >> 'math')
Rendered /home/mat/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/bundler/gems/active_admin-66de2f86ae1d/app/views/active_admin/resource/index.html.arb (32.7ms)
Completed 500 Internal Server Error in 47ms

ActiveRecord::StatementInvalid - PG::UndefinedFunction: ERROR: operator does not exist: character varying >> unknown
LINE 1: ...ECT COUNT(*) FROM "users" WHERE ("users"."email" >> 'math')
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT COUNT(*) FROM "users" WHERE ("users"."email" >> 'math'):
activerecord (4.0.3) lib/active_record/connection_adapters/abstract_adapter.rb:440:in `rescue in log'
activerecord (4.0.3) lib/active_record/connection_adapters/abstract_adapter.rb:430:in `log'
activerecord (4.0.3) lib/active_record/connection_adapters/postgresql/database_statements.rb:137:in `exec_query'
activerecord (4.0.3) lib/active_record/connection_adapters/postgresql_adapter.rb:891:in `select'
activerecord (4.0.3) lib/active_record/connection_adapters/abstract/database_statements.rb:24:in `select_all'
activerecord (4.0.3) lib/active_record/connection_adapters/abstract/query_cache.rb:61:in `block in select_all'
activerecord (4.0.3) lib/active_record/connection_adapters/abstract/query_cache.rb:76:in `cache_sql'
activerecord (4.0.3) lib/active_record/connection_adapters/abstract/query_cache.rb:61:in `select_all'
activerecord (4.0.3) lib/active_record/relation/calculations.rb:262:in `execute_simple_calculation'
activerecord (4.0.3) lib/active_record/relation/calculations.rb:224:in `perform_calculation'
activerecord (4.0.3) lib/active_record/relation/calculations.rb:108:in `calculate'
activerecord-deprecated_finders (1.0.3) lib/active_record/deprecated_finders/relation.rb:84:in `calculate'
activerecord (4.0.3) lib/active_record/relation/calculations.rb:24:in `count'
() home/mmat/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/bundler/gems/active_admin-66de2f86ae1d/lib/active_admin/helpers/collection.rb:11:in `collection_size'
() home/mmat/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/bundler/gems/active_admin-66de2f86ae1d/lib/active_admin/views/components/scopes.rb:62:in `get_scope_count'
() home/mmat/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/bundler/gems/active_admin-66de2f86ae1d/lib/active_admin/views/components/scopes.rb:40:in `block (3 levels) in build_scope'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:18:in `span'
() home/mmat/.rvm/gems/ruby-1.9.3-p392@rails3tutorial2ndEd/bundler/gems/active_admin-66de2f86ae1d/lib/active_admin/views/components/scopes.rb:39:in `block (2 levels) in build_scope'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'


Started POST "/__better_errors/70228353699700/variables" for 127.0.0.1 at 2014-03-01 17:45:43 +0100
User Load (0.7ms) SELECT "users".* FROM "users" WHERE ("users"."email" >> 'math') ORDER BY "users"."id" desc
PG::UndefinedFunction: ERROR: operator does not exist: character varying >> unknown
LINE 1: ...CT "users".* FROM "users" WHERE ("users"."email" >> 'math')...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT "users".* FROM "users" WHERE ("users"."email" >> 'math') ORDER BY "users"."id" desc

编辑

我不知道它是否与问题有关或者它是否有帮助,但作为 Active Admin 使用 Ransack,我认为它可能对我的 Ransack Initializer 中写的内容有用

Ransack.configure do |config|
%w[contained_within contained_within_or_equals contains contains_or_equals overlap].each do |p|
config.add_predicate p, arel_predicate: p, wants_array: true
end
end

最佳答案

It's like postgresql does not undertand the command Active Admin filter on string with 'contain' ask him to do.

对了,检查错误中的这些行:

PG::UndefinedFunction:错误:运算符不存在:字符变化>>未知
第 1 行:...ECT COUNT(*) FROM "users"WHERE ("users"."email">> 'math')

Postgres 被赋予运算符 >>> 以在用户表中的电子邮件列和搜索字符串 'math' 之间使用。可以使用哪些运算符取决于要查询的列的数据类型,您可以在数据库 CLI 中进行调查。在命令行中输入 rails dbconsole 并检查列的数据类型,我相信您可以使用:

从 INFORMATION_SCHEMA.COLUMNS 中选择 *

电子邮件通常存储为字符串。如果是这种情况,使用 >>> 就没有意义,因为它没有出现在 the Postgres documentation's list of operators for strings 中。 .这反过来又表明 ActiveAdmin 或其中一个依赖项误解了您的 contains

顺便说一下,您使用 :as =>:string 过滤的一些属性,比如 Person.name,可能是 ruby​​ String在您与他们打交道的水平上。 Active Admin's documentation seems to suggest those attributes' filter input elements would default to text fields ;是这样吗?如果您还没有,那么值得尝试删除它们,尽管这应该无关紧要。

关于ruby-on-rails - 在 :string not working on Active Admin (Rails 3. 2/postgresql 上过滤),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22117269/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com