Always display self, first, last pagination links

This commit is contained in:
mecampbellsoup
2017-06-05 17:23:34 -04:00
parent dff621e174
commit 7387266c37
2 changed files with 22 additions and 11 deletions

View File

@@ -35,19 +35,21 @@ module ActiveModelSerializers
private
def pages_from
return {} if collection.total_pages <= FIRST_PAGE
{}.tap do |pages|
pages[:self] = collection.current_page
pages[:self] = collection.current_page
pages[:first] = FIRST_PAGE
pages[:last] = collection.total_pages
unless collection.current_page == FIRST_PAGE
pages[:first] = FIRST_PAGE
pages[:prev] = collection.current_page - FIRST_PAGE
end
if collection.total_pages > 0
unless collection.current_page == FIRST_PAGE
pages[:prev] = collection.current_page - FIRST_PAGE
end
unless collection.current_page == collection.total_pages
pages[:next] = collection.current_page + FIRST_PAGE
pages[:last] = collection.total_pages
unless collection.current_page == collection.total_pages
pages[:next] = collection.current_page + FIRST_PAGE
end
else
pages[:last] = FIRST_PAGE
end
end
end