Module: RESTFramework::Mixins::ListModelMixin

Included in:
ModelControllerMixin, ReadOnlyModelControllerMixin
Defined in:
lib/rest_framework/mixins/model_controller_mixin.rb

Overview

Mixin for listing records.

Instance Method Summary collapse

Instance Method Details

#get_index_recordsObject

Get records with both filtering and pagination applied.



736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
# File 'lib/rest_framework/mixins/model_controller_mixin.rb', line 736

def get_index_records
  records = self.get_records

  # Handle pagination, if enabled.
  if paginator_class = self.class.paginator_class
    # Paginate if there is a `max_page_size`, or if there is no `page_size_query_param`, or if the
    # page size is not set to "0".
    max_page_size = self.class.max_page_size
    page_size_query_param = self.class.page_size_query_param
    if max_page_size || !page_size_query_param || params[page_size_query_param] != "0"
      paginator = paginator_class.new(data: records, controller: self)
      page = paginator.get_page
      serialized_page = self.serialize(page)
      return paginator.get_paginated_response(serialized_page)
    end
  end

  records
end

#indexObject



731
732
733
# File 'lib/rest_framework/mixins/model_controller_mixin.rb', line 731

def index
  render(api: self.get_index_records)
end