I want a custom date_range filter in Product model with activeadmin. Here my code
ActiveAdmin.register Product do
filter :version_creado_en, as: :date_range
class Product < ActiveRecord::Base
ransacker :version_creado_en , :formatter =>->(v) {
v_date = "2016-09-01".to_date
w_date = "2016-09-30".to_date
time_range = v_date ..w_date
results = Product.where({created_at:time_range} ).map(&:id)
results.present? ? results : nil
} do |parent|
parent.table[:id]
end
This apparently works because my log say:
Product Load (0.5ms) SELECT "products".* FROM "products" WHERE ("products"."created_at" BETWEEN '2016-09-01' AND '2016-09-30')
CACHE (0.0ms) SELECT "products".* FROM "products" WHERE ("products"."created_at" BETWEEN '2016-09-01' AND '2016-09-30') (0.5ms) SELECT COUNT() FROM "products" WHERE (("products"."id" >= 1, 2 AND "products"."id" <= 1, 2)) SQLite3::SQLException: near ",": syntax error: SELECT COUNT() FROM "products" WHERE (("products"."id" >= 1, 2 AND "products"."id" <= 1, 2)) Rendered /home/grados-sanchez/.rvm/gems/ruby-2.2.3/bundler/gems/activeadmin-74799b8652c6/app/views/active_admin/resource/index.html.arb (175.1ms) Completed 500 Internal Server Error in 186ms
ActionView::Template::Error (SQLite3::SQLException: near ",": syntax error: SELECT COUNT(*) FROM "products" WHERE (("products"."id" >= 1, 2 AND "products"."id" <= 1, 2))):
Here my code http://ift.tt/2cxh7tp
Aucun commentaire:
Enregistrer un commentaire