NotDan
NotDan

Reputation: 32223

How do I do paging of records with ruby on rails?

I want to do paging of lists of data with ruby on rails. Basically, I want to show only 20 records at a time, with next and back buttons. It would be nice, but not required, to show links for the page numbers.

Something like this would be nice:

<< Previous 1 2 3 4 5 ... Next >>

Is there a built in way to do this in ruby on rails (or something I can add) so I don't have to write this myself?

Upvotes: 3

Views: 5472

Answers (3)

Priyank
Priyank

Reputation: 14387

There is a plugin will_paginate that can be used to do pagination seamlessly in RoR. Find following links. They might be of some help.

http://nasir.wordpress.com/2007/10/31/pagination-in-ruby-on-rails-using-will_paginate-plugin/

https://github.com/mislav/will_paginate/wiki/

https://github.com/mislav/will_paginate/wiki/simple-search

http://blog.railsspace.com/past/2008/1/31/railsspace_will_paginate/

Also I am sure that following railscast by Ryan Bates is going to be an excellent source of understanding. All rails casts are really good and give you deep understanding of basics. http://railscasts.com/episodes/51-will-paginate

Upvotes: 5

Sambhav Sharma
Sambhav Sharma

Reputation: 5860

kaminari has a much cleaner interface. It is more active than will_paginate, has 50% more commits and double the contributors as of now.

Ruby tool box gives a good view of numbers about both. Also there is a kaminari-bootstrap project as well. I suggest to take some time out, and read their documentation, and see which one fits your needs better.

Upvotes: 1

CrazyCoder
CrazyCoder

Reputation: 402095

will_paginate or similar would be a good start.

Upvotes: 4

Related Questions