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
-
#get_index_records ⇒ Object
Get records with both filtering and pagination applied.
- #index ⇒ Object
Instance Method Details
#get_index_records ⇒ Object
Get records with both filtering and pagination applied.
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 |
# File 'lib/rest_framework/mixins/model_controller_mixin.rb', line 755 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 |
#index ⇒ Object
750 751 752 |
# File 'lib/rest_framework/mixins/model_controller_mixin.rb', line 750 def index render(api: self.get_index_records) end |