activeadmin 和 acts_as_taggable_on 生成 ambiguous_column_name 错误

activeadmin and acts_as_taggable_on generates ambiguous_column_name error

我正在使用 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')

我该如何解决这个问题?

事实证明 active_admin 使用搜查 gem 来处理它的过滤器。我必须在模型中自定义 "ransackers" 才能完成这项工作:

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/