Class: RESTFramework::RansackFilter
- Inherits:
-
BaseFilter
- Object
- BaseFilter
- RESTFramework::RansackFilter
- Defined in:
- lib/rest_framework/filters/ransack.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::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.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 distinct_from_query = ActiveRecord::Type::Boolean.new.cast( @controller.request.query_parameters[distinct_query_param], ) unless distinct_from_query.nil? distinct = distinct_from_query end end return data.ransack(q, @controller.).result(distinct: distinct) end return data end |