Rather than merging it into your project only to be immediately thrown away in favour of the actual will_paginate
, here's a demo in a very simple sample app (just a Things#index
) that we can go over in isolation. Check it out here.
The "plumbing" here is relatively simple:
-
Provide
paginate
as a class-method on a model by manuallyextend
ing the model with a module -
Store pagination info (
page
,total_pages
, etc.) as an attribute on the scope/relation (allowing it to be retrieved in the view helper)
Also includes some simple views, with associated helper
, so this is effectively a full solution to the assignment.
To test out:
-
git clone
this repo -
bundle install
-
rake db:migrate
-
rake db:seed
-
rails s
-
Navigate to http://localhost:3000/things
-
Click the pagination links and reflect