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.
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 |
# File 'lib/rest_framework/mixins/model_controller_mixin.rb', line 698 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 |
#index ⇒ Object
693 694 695 |
# File 'lib/rest_framework/mixins/model_controller_mixin.rb', line 693 def index return render_api(self.get_index_records) end |