I've noticed that pagination gems like mislav-will_paginate
are quite popular. Is this because Rails does not have a built-in pagination solution or because the built-in solution is not very good?

- 291
- 1
- 3
- 3
-
1will_paginate is pretty much actually the "built-in" solution these days/ – Toby Hede Jun 09 '09 at 10:24
-
Seems searchlogic uses will_paginate, so you don't need to use searchlogic to get it. It looks pretty cool, though. http://rdoc.info/github/binarylogic/searchlogic/master/file/README.rdoc#Pagination_(leverage_will_paginate) – calasyr Oct 30 '10 at 01:25
4 Answers
In Rails 2.0 the pagination ability of ActionController was removed and turned into a plugin for backwards compatibility called 'classic_pagination'. However, from my searches for a pagination solution for myself the consensus seems to be that using 'classic_pagination' is not optimal.
After watching a couple of podcasts and after several recommendations I opted to try the will_paginate plugin and haven't looked back. It's fast, easy to use and well-maintained.
I believe that even V2 of Searchlogic recommends its use.

- 34,448
- 50
- 182
- 322

- 471
- 3
- 3
-
I came to the same conclusion. The railscasts tutorial on will_paginate was quiet helpful as well. – tstyle Apr 27 '11 at 07:49
If you are using Rails 3 Kaminari plugin will be very handy for pagination. Github Railscasts

- 36,389
- 27
- 134
- 170
-
+1 for Kaminari. I was using will_paginate but Kaminari is much nicer. – kakubei Jun 27 '12 at 10:17
Rails has built-in pagination, but it's a simple module and not suitable for all needs. Unless you have specific pagination needs in mind though, it should suit most purposes.

- 25,101
- 4
- 35
- 56
I'd recommend searchlogic. It has pagination built in and many other nices things.
- Easy filtering
- Pagination
- Sorting
And.. for all of that nice helpers.
Code says more than thousand words (dont get confused by the HAML example, you can use normal erb templates if you prefer them, the code/structure is the same):
Controller:
def index
@search = User.new_search(params[:search])
@users, @users_count = @search.all, @search.count
end
Pagination stuff in the view:
== Per page: #{per_page_select}
== Page: #{page_select}
Sort as/by in view:
- unless @users_count.zero?
%table
%tr
%th= order_by_link :account => :name
%th= order_by_link :first_name
%th= order_by_link :last_name
%th= order_by_link :email
- @users.each do |user|
%tr
%td= user.account? ? user.account.name : "-"
%td= user.first_name
%td= user.last_name
%td= user.email
Easy, simple and quick filters:
- form_for @search do |f|
- f.fields_for @search.conditions do |users|
= users.text_field :first_name_contains
= users.date_select :created_after
- users.fields_for users.object.orders do |orders|
= orders.select :total_gt, (1..100)
= f.submit "Search"
And everything works together, so changing a page and then the sorting, and adding a filter works without losing any of the other settings :).
All you need is in your environment.rb:
config.gem "searchlogic"
and install it with: rake gems:install
Also checkout the online example

- 16,189
- 7
- 53
- 67
-
How does this compare to the numerous other pagination solutions? Why choose this over the others? – propstop Jun 08 '09 at 22:52
-
Well, the previous thing I used was will_paginate, which used to be the default paginator. The beauty of searchlogic is a) that everything is integrated (you don't have to get paginator work together filtering/sorting, this is done automatically/magically). And b) it's pretty actively developed atm and it looks quite mature. c) the developer produces very nice and intuitive libraries, I would also recommend his auth library 'authlogic'. In the documentation you'll find some remarks why authlogic is 'better' than the other auth plugins :). But just try them out in one of your data views.. – reto Jun 09 '09 at 08:03
-
And his blog post: http://www.binarylogic.com/2009/06/09/searchlogic-v2-beta-released/ I still stick with my opinion that searchlogicv1 is a very nice library, and so far it hasn't let me down :). – reto Jun 09 '09 at 08:09
-
1
-
what makes you say that? I guess it isn't ready yet, but are there other reasons against a rails3/searchlogic combo? – reto Apr 14 '10 at 09:05
-
@reto It's just not compatible. There's a port called rd_searchlogic and there's another similar project that I recommend called meta_search. – graywh Mar 01 '12 at 16:20