Class: ActionController::Base
- Inherits:
-
Object
- Object
- ActionController::Base
- Defined in:
- lib/search_autocomplete/searchable.rb
Overview
Searchable
Direct Known Subclasses
Instance Method Summary collapse
-
#search(model, approximate_fields = [], exact_fields = [], include_list = nil) ⇒ Object
Performs a search on the model based on permitted fields.
Instance Method Details
#search(model, approximate_fields = [], exact_fields = [], include_list = nil) ⇒ Object
Performs a search on the model based on permitted fields
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/search_autocomplete/searchable.rb', line 14 def search(model, approximate_fields = [], exact_fields = [], include_list = nil) arel_table = model.arel_table search_conditions = prepare_search_fields arel_table, exact_fields search_conditions += prepare_search_fields(arel_table, approximate_fields, false) query = include_list.present? ? model.includes(include_list) : model query = query.where(*search_conditions) if search_conditions.length.positive? query end |