-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add pagination helper for generating navigat
- Loading branch information
1 parent
7b3d8c3
commit 29e1e9f
Showing
1 changed file
with
17 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |