Skip to content

Instantly share code, notes, and snippets.

@anilnabin25
Created January 4, 2024 06:31
Show Gist options
  • Save anilnabin25/6fc94ae2c1a6ad61b7edc31654a3e102 to your computer and use it in GitHub Desktop.
Save anilnabin25/6fc94ae2c1a6ad61b7edc31654a3e102 to your computer and use it in GitHub Desktop.
Create custom filter with custom attribute.
```app/models/concerns/active_admin/filter_name.rb```
module ActiveAdmin::FilterName
extend ActiveSupport::Concern
included do
def self.ransackable_scopes(_auth_object = nil)
%i[attribute_eq]
end
def self.attribute_eq(paramater)
return none unless invalid_parameter
where('table_name.attribute >= ?', paramater)
end
end
end
```app/models/model_name.rb```
class ModelName < ApplicationRecord
include ActiveAdmin::FilterName
end
``` now you can use the customer filter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment