3

active_adminとacts_As_taggable_onを使用していますが、フィルタを作成しようとしています。ここでactiveadminとacts_as_taggable_onはambiguous_column_nameエラーを生成します

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') 

を?

+0

問題があります'created_at> '2017-01-17 00:22:53.923894'' ' created_at'は 'taggings'と' people'の両方に存在します – TheRealMrCrowley

+0

あなたはその呼び出しが行われたコードを投稿できますか?何かが見つからないように思える – TheRealMrCrowley

答えて

0

active_adminは、ransack 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/

関連する問題