自定义筛选器activeadmin无法正常工作

时间:2016-09-16 22:47:11

标签: ruby-on-rails activerecord activeadmin

我正在尝试使用有效的管理员制作自定义过滤器。这是我设置硬编码的代码。

filter :versions_created, as: :date_range, label: "Resolvido em"

ransacker :versions_created, formatter: proc { |v,w|
  v_date = "2016-09-09".to_date
  w_date = "2016-09-09".to_date
  time_range = v_date ..w_date
  results = Occurrences.where({created_at:time_range} ).map(&:id)
  results.present? ? results : nil
}do |parent|
parent.table[:id]
end

这显然有效,因为我的日志说:

  //IS CORRECT
  Occurrence Load (0.6ms)  SELECT "occurrences".* FROM "occurrences" WHERE ("occurrences"."created_at" BETWEEN '2016-09-09' AND '2016-09-09')
  CACHE (0.0ms)  SELECT "occurrences".* FROM "occurrences" WHERE  ("occurrences"."created_at" BETWEEN '2016-09-09' AND '2016-09-09')
  //HEREEEE THE PROBLEM
  *(0.5ms)  SELECT COUNT(*) FROM "occurrences" WHERE ("occurrences"."id" >= NULL AND "occurrences"."id" <= NULL)
  (0.6ms)  SELECT COUNT(count_column) FROM (SELECT  1 AS count_column FROM "occurrences" WHERE ("occurrences"."id" >= NULL AND "occurrences"."id" <= NULL) LIMIT 30 OFFSET 0) subquery_for_count*

我的问题是你知道为什么其他两个查询的值为NULL吗?

0 个答案:

没有答案