Module: Headmin::Filterable
- Defined in:
- app/controllers/concerns/headmin/filterable.rb
Instance Method Summary collapse
- #default_filter_types ⇒ Object
-
#filter(collection, filter_types = {}) ⇒ Object
Will create a Headmin::Filters object with a default configuration for “id” and “search”.
Instance Method Details
#default_filter_types ⇒ Object
20 21 22 23 24 25 |
# File 'app/controllers/concerns/headmin/filterable.rb', line 20 def default_filter_types { id: :number, search: :search } end |
#filter(collection, filter_types = {}) ⇒ Object
Will create a Headmin::Filters object with a default configuration for “id” and “search”
Example:
orders = Order orders = filter(orders, {
status: :text,
price: :number,
in_stock: :boolean
})
15 16 17 18 |
# File 'app/controllers/concerns/headmin/filterable.rb', line 15 def filter(collection, filter_types = {}) type_hash = default_filter_types.merge(filter_types) Headmin::Filters.new(params, type_hash).query(collection) end |