From fd66781fd3ce3f7839c13270e492be5de7af97cc Mon Sep 17 00:00:00 2001 From: Ruxton Date: Fri, 3 Jul 2020 11:12:33 +0800 Subject: [PATCH] Allow sorting --- lib/ransack/adapters/mongoid/ransack/visitor.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/ransack/adapters/mongoid/ransack/visitor.rb b/lib/ransack/adapters/mongoid/ransack/visitor.rb index a6a507c..6bc4e59 100644 --- a/lib/ransack/adapters/mongoid/ransack/visitor.rb +++ b/lib/ransack/adapters/mongoid/ransack/visitor.rb @@ -14,5 +14,13 @@ def quoted?(object) end end + def visit_Ransack_Nodes_Sort(object) + if object.valid? + object.context.object.options[:sort] = {"#{object.name}": object.dir} + else + scope_name = :"sort_by_#{object.name}_#{object.dir}" + scope_name if object.context.object.respond_to?(scope_name) + end + end end end