Skip to content

Commit

Permalink
feat: Add pagination helper for generating navigat
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] authored Feb 3, 2024
1 parent 7b3d8c3 commit 29e1e9f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/helpers/pagination_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module PaginationHelper
def paginate(total_items, items_per_page, current_page, base_url)
total_pages = (total_items.to_f / items_per_page).ceil
pagination_html = '<ul class="pagination">'

if current_page > 1
pagination_html += '<li>' + link_to('Previous', "#{base_url}?page=#{current_page - 1}") + '</li>'
end

if current_page < total_pages
pagination_html += '<li>' + link_to('Next', "#{base_url}?page=#{current_page + 1}") + '</li>'
end

pagination_html += '</ul>'
pagination_html.html_safe
end
end

0 comments on commit 29e1e9f

Please sign in to comment.