Module: RESTFramework::ListModelMixin

Included in:
ModelControllerMixin, ReadOnlyModelControllerMixin
Defined in:
lib/rest_framework/controller_mixins/models.rb

Overview

Mixin for listing records.

Instance Method Summary collapse

Instance Method Details

#indexObject



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/rest_framework/controller_mixins/models.rb', line 172

def index
  @records = self.get_filtered_data(self.get_recordset)

  # Handle pagination, if enabled.
  if self.class.paginator_class
    paginator = self.class.paginator_class.new(data: @records, controller: self)
    page = paginator.get_page
    serialized_page = self.get_serializer_class.new(object: page, controller: self).serialize
    data = paginator.get_paginated_response(serialized_page)
  else
    data = self.get_serializer_class.new(object: @records, controller: self).serialize
  end

  return api_response(data)
end