Class: CurrentScope::SubjectsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/current_scope/subjects_controller.rb

Constant Summary collapse

PER_PAGE =
50
SEARCH_COLUMNS =

Identity columns searched by ?q=, in the same preference order as current_scope_subject_label's default chain. Intersected with the subject table's real column_names before use, so a query never spans a page.

%w[email email_address name first_name last_name].freeze

Instance Method Summary collapse

Instance Method Details

#indexObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/current_scope/subjects_controller.rb', line 10

def index
  klass = CurrentScope.config.subject_class.constantize
  @query = params[:q].to_s.strip
  scope = filter_subjects(klass.order(:id), @query)

  @page = [ params[:page].to_i, 1 ].max
  @subjects = scope.limit(PER_PAGE).offset((@page - 1) * PER_PAGE)
  @has_next_page = scope.offset(@page * PER_PAGE).exists?

  @roles = Role.order(:name)
  @assignments = RoleAssignment.where(subject: @subjects)
                               .index_by { |a| [ a.subject_type, a.subject_id ] }
  @scoped = ScopedRoleAssignment.where(subject: @subjects)
                                .includes(:role, :resource)
                                .group_by { |a| [ a.subject_type, a.subject_id ] }
end