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



224
225
226
# File 'lib/rest_framework/controller_mixins/models.rb', line 224

def index
  api_response(self.index!)
end

#index!Object



228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/rest_framework/controller_mixins/models.rb', line 228

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(page, controller: self).serialize
    return paginator.get_paginated_response(serialized_page)
  else
    return self.get_serializer_class.new(@records, controller: self).serialize
  end
end