Class: Effective::SearchController

Inherits:
ApplicationController
  • Object
show all
Includes:
CrudController
Defined in:
app/controllers/effective/search_controller.rb

Instance Method Summary collapse

Instance Method Details

#build_searchObject



23
24
25
26
27
28
# File 'app/controllers/effective/search_controller.rb', line 23

def build_search
  search = EffectiveSearch.Search.new()
  search.assign_attributes(search_params.select { |k, _| search.respond_to?("#{k}=") })
  search.assign_attributes(current_user: current_user, view_context: view_context)
  search
end

#indexObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/effective/search_controller.rb', line 9

def index
  EffectiveResources.authorize!(self, :index, EffectiveSearch.Search)

  # But more often we do a full membership directory search screen
  @search = build_search
  @search.search!

  if @search.present?
    @page_title = "Search results for ‘#{@search}’".html_safe
  else
    @page_title = "Search"
  end
end

#search_paramsObject



30
31
32
33
34
35
36
37
38
# File 'app/controllers/effective/search_controller.rb', line 30

def search_params
  return {} unless params[:q].present?

  if params[:q].respond_to?(:to_h)      # From the search form
    params.require(:q).permit!
  else
    { term: params.permit(:q).fetch(:q) }   # From the url /directory?q=asdf
  end
end