Last active
October 24, 2019 11:42
-
-
Save amitsaxena/f70768b0bb935278a0900607b85639cb to your computer and use it in GitHub Desktop.
How to write an Active Admin custom filter (custom search)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveAdmin.register MyModel do | |
filter :custom_field, :as => :string, :label => "Custom Field Display Name" | |
end | |
class MyModel < ActiveRecord::Base | |
search_methods :custom_field_search | |
def self.custom_field_search(name) | |
# This method should return an ActiveRecord::Relation Object with MyModel objects | |
# Put in your complex search logic here | |
objects = Model2.where(:user_type => "Student").where('_name like ?', "%#{name}%") | |
MyModel.where(:id => objects.map{|u| u.user_id}) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I guess this was for an older version of
active_admin
. I don't use it any longer to be able to debug and fix it.