Skip to content

Commit

Permalink
fix for count in Pagy::Backend (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Jun 1, 2018
1 parent cc39fea commit 8a204dc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/api/backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ For example: here is a `pagy` method that doesn't call any sub-method, that may

```ruby
def pagy_custom(collection, vars={})
pagy = Pagy.new(count: collection.count, page: params[:page], **vars)
pagy = Pagy.new(count: collection.count(:all), page: params[:page], **vars)
return pagy, collection.offset(pagy.offset).limit(pagy.items)
end
```
Expand All @@ -63,7 +63,7 @@ Here is its source:
# sub-method called only by #pagy: here for easy customization of variables by overriding
def pagy_get_vars(collection, vars)
# return the merged variables to initialize the pagy object
{ count: collection.count,
{ count: collection.count(:all),
page: params[vars[:page_param]||VARS[:page_param]] }.merge!(vars)
end
```
Expand Down
4 changes: 2 additions & 2 deletions docs/how-to.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ end
def cache_count(collection)
cache_key = "pagy-#{collection.model.name}:#{collection.to_sql}"
Rails.cache.fetch(cache_key, expires_in: 20 * 60) do
collection.count
collection.count(:all)
end
end

Expand All @@ -353,7 +353,7 @@ You can do so by setting the `:item_path` variable to the path to lookup in the
1. by overriding the `pagy_get_vars` method in your controller (valid for all the pagy instances) adding the `:item_path`. For example (with ActiveRecord):
```ruby
def pagy_get_vars(collection, vars)
{ count: collection.count,
{ count: collection.count(:all),
page: params[vars[:page_param]||Pagy::VARS[:page_param]],
item_path: "activerecord.models.#{collection.model_name.i18n_key}" }.merge!(vars)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pagy/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def pagy(collection, vars={})
# sub-method called only by #pagy: here for easy customization of variables by overriding
def pagy_get_vars(collection, vars)
# return the merged variables to initialize the pagy object
{ count: collection.count,
{ count: collection.count(:all),
page: params[vars[:page_param]||VARS[:page_param]] }.merge!(vars)
end

Expand Down

0 comments on commit 8a204dc

Please sign in to comment.