From 3d36ebe2e68109d7a4cb397464018683d58990aa Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 12 Nov 2015 18:29:19 +1100 Subject: [PATCH] Some Ransack trickery to get OrderCycles#index to load only recent OR undated OCs when no orders_close_at predicate is passed in --- app/controllers/admin/order_cycles_controller.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/order_cycles_controller.rb b/app/controllers/admin/order_cycles_controller.rb index 7119490942..ec3954a436 100644 --- a/app/controllers/admin/order_cycles_controller.rb +++ b/app/controllers/admin/order_cycles_controller.rb @@ -113,8 +113,12 @@ module Admin private def load_data_for_index @show_more = !!params[:show_more] - params[:q] ||= {} - params[:q][:orders_close_at_null_or_orders_close_at_gt] = 31.days.ago unless @show_more || params[:q][:orders_close_at_gt].present? + unless @show_more || params[:q].andand[:orders_close_at_gt].present? + # Split ransack params into all those that currently exist and new ones to limit returned ocs to recent or undated + params[:q] = { + g: [ params.delete(:q) || {}, { m: 'or', orders_close_at_gt: 31.days.ago, orders_close_at_null: true } ] + } + end @order_cycle_set = OrderCycleSet.new :collection => (@collection = collection) end