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
-
#get_index_records ⇒ Object
Helper to get records with both filtering and pagination applied.
- #index ⇒ Object
Instance Method Details
#get_index_records ⇒ Object
Helper to get records with both filtering and pagination applied.
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
# File 'lib/rest_framework/controller_mixins/models.rb', line 417 def get_index_records records = self.get_records # Handle pagination, if enabled. if self.class.paginator_class # If there is no `max_page_size`, `page_size_query_param` is not `nil`, and the page size is # set to "0", then skip pagination. unless !self.class.max_page_size && self.class.page_size_query_param && params[self.class.page_size_query_param] == "0" 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 end return records end |
#index ⇒ Object
412 413 414 |
# File 'lib/rest_framework/controller_mixins/models.rb', line 412 def index return api_response(self.get_index_records) end |