gpt4 book ai didi

activerecord - activeadmin 和 acts_as_taggable_on 生成 ambiguous_column_name 错误

转载 作者:行者123 更新时间:2023-12-02 04:36:45 26 4
gpt4 key购买 nike

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

关于activerecord - activeadmin 和 acts_as_taggable_on 生成 ambiguous_column_name 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41818052/

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