Module: Railsful::Interceptors::Pagination
- Included in:
- Serializer
- Defined in:
- lib/railsful/interceptors/pagination.rb
Overview
Interceptor that paginates a given ActiveRecord::Relation with help of the Kaminari gem.
Instance Method Summary collapse
Instance Method Details
#pagination_options(options) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/railsful/interceptors/pagination.rb', line 12 def () # Check if json value should be paginated. return unless paginate?() # Get the relation from options hash so we can paginate it and # check the total count. relation = .fetch(:json) # Paginate the relation and store new relation in temporary variable. paginated = paginate(relation) # Create a meta hash = { total_pages: paginated.try(:total_pages), total_count: paginated.try(:total_count), current_page: paginated.try(:current_page), next_page: paginated.try(:next_page), prev_page: paginated.try(:prev_page) } .deeper_merge( links: links(paginated), meta: ).merge(json: paginated) end |
#render(options) ⇒ Object
8 9 10 |
# File 'lib/railsful/interceptors/pagination.rb', line 8 def render() super(()) end |