Class: Admin::SearchController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- Admin::SearchController
- Defined in:
- lib/generators/open_loam/install/templates/admin/search_controller.rb
Overview
One box, every entity. Results are grouped by entity and limited per group, so a broad query stays readable and cheap.
Tenant isolation needs no work here: each model's search returns its own
tenant-scoped relation, so this can only ever find records the current
tenant owns.
Constant Summary collapse
- PER_ENTITY =
10
Constants included from Pagination
Instance Method Summary collapse
- #index ⇒ Object
-
#search_result_label(record) ⇒ Object
The first searchable column that has a value, plus the id — enough to recognise a record without OpenLoam having to know what a "title" is.
Methods inherited from BaseController
Methods included from Pagination
Instance Method Details
#index ⇒ Object
15 16 17 18 |
# File 'lib/generators/open_loam/install/templates/admin/search_controller.rb', line 15 def index @query = params[:q].to_s.strip @results = @query.blank? ? {} : search_all(@query) end |
#search_result_label(record) ⇒ Object
The first searchable column that has a value, plus the id — enough to recognise a record without OpenLoam having to know what a "title" is.
22 23 24 25 26 |
# File 'lib/generators/open_loam/install/templates/admin/search_controller.rb', line 22 def search_result_label(record) value = record.class.open_loam_searchable_columns.filter_map { |column| record.public_send(column).presence }.first [ value || record.model_name.human, "##{record.id}" ].join(" ") end |