Custom search with ransacker

后端 未结 2 1309
孤独总比滥情好
孤独总比滥情好 2020-12-25 08:01

I\'m trying to add a custom filter to ActiveAdmin which is powered by Ransack these days. Unfortunately, ransacker is not documented at all and from the few res

2条回答
  •  长情又很酷
    2020-12-25 08:47

    There's a feature for ransackable scopes waiting to be merged: https://github.com/activerecord-hackery/ransack/pull/288

    UPDATE:

    I've given the work of avit and glebm another go with PR https://github.com/activerecord-hackery/ransack/pull/390 which has been merged, it's therefore now possible to use scopes with Ransack. For the documentation, see the commit:

    https://github.com/svoop/ransack/commit/72dd5d12d58919bf37199234cf13f9533f3b8cd5

    Here's a real-life example:

    class Project < ActiveRecord::Base
      scope :full_text_search, ->(search) { search_in_all_translated(search) }
    
      def self.ransackable_scopes(auth_object = nil)
        [:full_text_search]
      end
    end
    

    In this example search_in_all_translated returns some complex indexed full text search SQL.

提交回复
热议问题