我正在使用active_admin和acts_As_taggable_on,并且我正在尝试制作一个过滤器。以下是模型代码:
class Person < ApplicationRecord
acts_as_taggable_on :expertise, :industry
end下面是过滤器:
filter :industry, as: :select, collection: Person.industry_counts.pluck(:name, :name)下面是我在提交过滤器时得到的错误:
SQLite3::SQLException: ambiguous column name: created_at: SELECT COUNT(DISTINCT "people"."id") FROM "people" LEFT OUTER JOIN "taggings" ON "taggings"."taggable_id" = "people"."id" AND "taggings"."context" = ? AND "taggings"."taggable_type" = ? WHERE "taggings"."tag_id" = 0 AND (created_at > '2017-01-17 00:22:53.923894')我该如何解决这个问题?
发布于 2017-02-07 07:12:38
事实证明,active_admin使用ransack gem来处理它的过滤器。我必须在模型中定制“搜索器”才能做到这一点:
def self.in_industry(industries)
Person.tagged_with(industries, :any => true, :on => :industry).select{|a| a} #use select to convert relation to array
end
ransacker :by_industry, formatter: proc{ |v|
data = Person.in_industry(v).map(&:id)
data = data.present? ? data : nil
} do |parent|
parent.table[:id]
end这是我从下面的文章和评论中得到的更正:
http://nikhgupta.com/code/activeadmin/custom-filters-using-ransacker-in-activeadmin-interfaces/
https://stackoverflow.com/questions/41818052
复制相似问题