lib/geared_pagination/controller.rb in geared_pagination-0.1 vs lib/geared_pagination/controller.rb in geared_pagination-0.2
- old
+ new
@@ -5,10 +5,11 @@
module Controller
extend ActiveSupport::Concern
included do
after_action :set_paginated_headers
+ etag { @page if geared_page? }
end
private
def set_page_and_extract_portion_from(records, per_page: nil)
@page = current_page_from(records, per_page: per_page)
@@ -18,10 +19,14 @@
def current_page_from(records, per_page: nil)
GearedPagination::Recordset.new(records, per_page: per_page).page(current_page_param)
end
def set_paginated_headers
- GearedPagination::Headers.new(page: @page, controller: self).apply if @page.is_a?(GearedPagination::Page)
+ GearedPagination::Headers.new(page: @page, controller: self).apply if geared_page?
+ end
+
+ def geared_page?
+ @page.is_a? GearedPagination::Page
end
def current_page_param
params[:page].to_i > 0 ? params[:page].to_i : 1
end