will_paginate

https://github.com/mislav/will_paginate

Ruby

Pagination library for Rails and other Ruby applications

WillPaginate::Collection#replace

This is a magic wrapper for the original Array#replace method. It serves
for populating the paginated collection after initialization.

Why magic? Because it tries to guess the total number of entries judging
by the size of given array. If it is shorter than +per_page+ limit, then we
know we're on the last page. This trick is very useful for avoiding
unnecessary hits to the database to do the counting after we fetched the
data for the current page.

However, after using +replace+ you should always test the value of
+total_entries+ and set it to a proper value if it's +nil+. See the example
in +create+.

Source | Google | Stack overflow

Edit

git clone [email protected]:mislav/will_paginate.git

cd will_paginate

open lib/will_paginate/collection.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-WillPaginate--Collection-replace-for-pr


# Commit to git

git add lib/will_paginate/collection.rbgit commit -m "better docs for WillPaginate::Collection#replace"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-WillPaginate--Collection-replace-for-pr

hub pull-request


# Celebrate!