Created
January 4, 2024 06:31
-
-
Save anilnabin25/6fc94ae2c1a6ad61b7edc31654a3e102 to your computer and use it in GitHub Desktop.
Create custom filter with custom attribute.
This file contains 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
```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