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.



729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
# File 'lib/rest_framework/mixins/model_controller_mixin.rb', line 729

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

  return records
end

#indexObject



724
725
726
# File 'lib/rest_framework/mixins/model_controller_mixin.rb', line 724

def index
  render(api: self.get_index_records)
end