Class: Effective::MembershipDirectoryController

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

Instance Method Summary collapse

Instance Method Details

#build_membership_directoryObject



19
20
21
22
23
# File 'app/controllers/effective/membership_directory_controller.rb', line 19

def build_membership_directory
  directory = EffectiveMemberships.MembershipDirectory.new(search_params)
  directory.current_user = current_user
  directory
end

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/effective/membership_directory_controller.rb', line 5

def index
  @page_title = 'Directory'
  EffectiveResources.authorize!(self, :index, Effective::Membership)

  # Sometimes we just display a Datatable for the membership directory
  @datatable = EffectiveResources.best('EffectiveMembershipsDirectoryDatatable').new

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

  @memberships = @membership_directory.results(page: params[:page])
end

#search_paramsObject



25
26
27
28
29
30
31
32
33
# File 'app/controllers/effective/membership_directory_controller.rb', line 25

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