Skip to content

Commit

Permalink
Merge pull request #53 from ifad/bugfix/fix-pagination
Browse files Browse the repository at this point in the history
Improve pagination
  • Loading branch information
tagliala authored Jan 23, 2024
2 parents fb9652d + be6d49f commit 11a6c07
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
5 changes: 0 additions & 5 deletions .rubocop_todo.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions lib/hawk/model/pagination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ module Model
module Pagination
module Common
def current_page
limit_value == 0 ? 1 : (offset_value / limit_value) + 1
if limit_value == 0
1
else
(offset_value / limit_value) + 1
end
end
end

Expand All @@ -14,12 +18,9 @@ def self.included(base)
base.instance_eval do
include Kaminari::ConfigurationMethods

eval <<-RUBY, binding, __FILE__, __LINE__ + 1
def #{Kaminari.config.page_method_name}(num = nil)
limit(default_per_page).
offset(default_per_page * ([num.to_i, 1].max - 1))
end
RUBY
define_singleton_method Kaminari.config.page_method_name do |num = nil|
limit(default_per_page).offset(default_per_page * ([num.to_i, 1].max - 1))
end
end
end

Expand Down

0 comments on commit 11a6c07

Please sign in to comment.