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.
Now lets add pagination support to an imaginary page listing all the clients
The code <%= will_paginate @clients %> 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.