#51 will_paginate (revised)
Almost every Rails application needs pagination, and will_paginate is a great way to go. Here I show you how to set it up, customize the way it looks, and see how it compares with Kaminari.
- Download:
- source codeProject Files in Zip (85.8 KB)
- mp4Full Size H.264 Video (18.2 MB)
- m4vSmaller H.264 Video (9.89 MB)
- webmFull Size VP8 Video (9.21 MB)
- ogvFull Size Theora Video (25.5 MB)
I'm aware of the Kaminari + will_paginate breakage in scenarios like when using activeadmin and I'll try to do something about it.
The way you customized previous/next labels, Ryan, is now deprecated. You should customize text via your app's locale files
Is there any workaround for using will_paginate with active_admin?
Thanks for great screencast. Loving the Pro service!
One question regarding pagination. Is it possible to paginate within limited set of records. Eg. If my table contains 300 records and i only want to show the first 100 records to users and then paginate only on those 100 records?
That doesn't work. It still paginate on all the 300 recordss
Can't see Railscasts pro in rss feed :(
There is a special pro feed you need to subscribe to.
Go to http://railscasts.com/pro , click "Manage you subscription" and then click "RSS Feed" (follow the instructions there to add the feed to iTunes)
I have a question about pagination on large sets, on the order of 100 million.
Both will_paginate and Kaminari count the records to count the number of pages that are necessary, and since I am using Postgres counts are god-awful slow.
I've hacked around it with a smart partial that will create an infinite paginator if the query will return over 5000 records (this number was chosen because 5000 can be counted quickly, and I feel confident that people won't browse through 5000 records without narrowing their search).
Anyone have any thoughts?
Thank you, Ryan Bates ... beauty, even in work, speaks for itself.
I have actually viewed and coded every single episode
... yes, play+pause+type, repeat ... the ASCIIcasts really help doing this.
It kind of helps to take the 'Monday' out of Mondays.
Will there be a script or something like ASCIIcasts for the pro versions ?
This is just a thought, not a criticism, but I was wondering if it might
be possible to purchase individual pro episodes ?
I mean a pricing scheme similar to renting movies/games at one of
those redbox kiosks ... a $1 is a great price. In this area they have
really caught on at grocery stores and 7-11's ... I almost expect to
see one on my porch one day. I think a recurring payment might be
a barrier to some, especially during these troubled times ... just a thought.
Thank you again.
hello ryan,
i'm trying to paginate an array that is returned by this statement?
InstructorRegistration.where(:joins => :user, :order => 'users.last_name')
been tryin few of the options mentioned online but not sure if these are still supported in this version of the gem...
thanks in advance
with rails3
instead of
InstructorRegistration.where(:joins => :user, :order => 'users.last_name')
I think you want
InstructorRegistration.joins(:user).order('users.last_name').paginate
Hi,
does anyone have a good solution to modify the will_paginate paging urls?
old:
.../products?page=2
new:
.../products/page/2/
I find out a easy solution. Just edit your routes.rb file like this:
But there is another problem. I got 2 different display styles (grid and list).
When I try something like this:
I get the "pretty url" plus "?display=grid" =/
If you are displaying search results, you can paginate like this.
Before
After
Also, if you are displaying record counts in your views, those counts will now reset on every page. Here's how to get the starting count of the current page, from which you can easily continue the count for the current records displayed.
In this example, the count is a cell in a table row.
Before
After
Note my use of
current_page
. Other useful stuff that will_paginate provides:total_pages
per_page
offset
previous_page
next_page
To get the number of records on the current page, you can use
size
.One more thing!
If you're displaying the total number of records found like
@items.size
, then paginate will now show an incorrect count. That will show the count for records on current page.To get the count of all records found by the query, you'll want to do
@items.total_entries
.Ignore my above comment, you can simply use
@items.offset + 1
as your starting count :)What are you doing at this forum if you are not interested in programming?