Pagination is a technique of presenting large amount of data on the UI, allowing the users to navigate between pages/data in an easy way.
Being a java developer for so many years, I remember doing dirty logic to achieve pagination to using some very useful and advanced tag libraries like displaytag. What ever may be the technique, pagination is never been an easy task.
But when I started playing around with rails and I got a situation where I need to do some pagination. And I readily found a gem will_paginate and doing pagination on rails is a breeze.
Lets get started first by installing the gem.
|
sudo gem install will_paginate |
To check whether the plugin installed successfully or not, you can do the following in your rails console.
1 |
defined? WillPaginate |
Now lets add pagination support to an imaginary page listing all the clients
1 |
def list_clients |
and then render the pagination in the ui using this simple snippet
1 |
<h3>Clients</h3> |
The code will add the links to previous/next page along with the page numbers to naviage.
The next few lines of code is just to print the client details.
Emeka
September 7, 2008
Great!
Emeka
September 7, 2008
Great!
maxblacks
September 14, 2008
can you post some screen shots ?