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



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

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



34
35
36
37
38
39
40
41
42
# File 'app/controllers/effective/membership_directory_controller.rb', line 34

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

#showObject



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

def show
  @page_title = 'Directory'

  @membership = Effective::Membership.find_by_token(params[:id])

  EffectiveResources.authorize!(self, :show, @membership)
  EffectiveResources.authorize!(self, :show, @membership.owner)
end