Class: RESTFramework::Filters::RansackFilter
- Inherits:
-
BaseFilter
- Object
- BaseFilter
- RESTFramework::Filters::RansackFilter
- Defined in:
- lib/rest_framework/filters/ransack_filter.rb
Overview
Adapter for the ‘ransack` gem.
Instance Method Summary collapse
-
#get_filtered_data(data) ⇒ Object
Filter data according to the request query parameters.
Methods inherited from BaseFilter
Constructor Details
This class inherits a constructor from RESTFramework::Filters::BaseFilter
Instance Method Details
#get_filtered_data(data) ⇒ Object
Filter data according to the request query parameters.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rest_framework/filters/ransack_filter.rb', line 4 def get_filtered_data(data) q = @controller.request.query_parameters[@controller.ransack_query_param] if q.present? distinct = @controller.ransack_distinct # Determine if `distinct` is determined by query param. if distinct_query_param = @controller.ransack_distinct_query_param if distinct_query = @controller.request.query_parameters[distinct_query_param].presence distinct_from_query = ActiveRecord::Type::Boolean.new.cast(distinct_query) unless distinct_from_query.nil? distinct = distinct_from_query end end end return data.ransack(q, @controller. || {}).result(distinct: distinct) end return data end |