Class: RESTFramework::ModelSearchFilter
- Inherits:
-
BaseFilter
- Object
- BaseFilter
- RESTFramework::ModelSearchFilter
- Defined in:
- lib/rest_framework/filters.rb
Overview
Multi-field text searching on models.
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.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/rest_framework/filters.rb', line 78 def get_filtered_data(data) fields = @controller.send(:get_search_fields) search = @controller.request.query_parameters[@controller.class.search_query_param] # Ensure we use array conditions to prevent SQL injection. unless search.blank? return data.where( fields.map { |f| "CAST(#{f} AS CHAR) #{@controller.class.search_ilike ? "ILIKE" : "LIKE"} ?" }.join(" OR "), *(["%#{search}%"] * fields.length), ) end return data end |