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

#get_index_recordsObject

Helper to get records with both filtering and pagination applied.



236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/rest_framework/controller_mixins/models.rb', line 236

def get_index_records
  records = self.get_records

  # 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.serialize(page)
    return paginator.get_paginated_response(serialized_page)
  end

  return records
end

#indexObject



231
232
233
# File 'lib/rest_framework/controller_mixins/models.rb', line 231

def index
  return api_response(self.get_index_records)
end