#51 will_paginate
In edge rails (soon to be Rails 2.0), the built-in pagination has been moved into a plugin: classic_pagination. I recommend jumping over to the will_paginate plugin as shown in this episode.
- Download:
- mp4Full Size H.264 Video (12.9 MB)
- m4vSmaller H.264 Video (7.79 MB)
- webmFull Size VP8 Video (23.1 MB)
- ogvFull Size Theora Video (18.8 MB)
Definitely a good choice for pagination .... Great tutorial as usual!
neat!~
+1, great cast!
ф пятерке!
Using Rails Edge almoust month. It really rocks :).
Thats good railscast too. Just thought that i should search something about pagination tomorrow.
Aaah very cool. How could we combine this with a List sort function?
I've been using paginate_find and it works pretty well. Have any opinions/experience with that plugin?
The paginate in the model ability from will_paginate looks really cool.
@riki, not exactly sure what you're referring to. You can pass an ":order" option just like the "find" method so you can do any sorting you wish.
@dave, I haven't used paginating_find but it looks pretty good.
Does will_paginate do AJAX pagination? Paginating_find does not (currently) and if will_paginate can do this I may migrate to it.
@lisa, nope, AFAIK will_paginate doesn't offer anything special in regards to AJAX. You can still use the back end part of the plugin to manage the pagination, however, you may need to rewrite the view portion to use link_to_remote instead of normal links.
"kinda" rails related, but a short screencast of how you do your shortcut magic in textmate might be cool.
Lisa - it's pretty easy to write a helper to do your AJAX pagination. There's a good example in the (awesome) exception_logger plugin. It's designed for classic pagination, but something like this would work for will_paginate, too. Check it out: http://svn.techno-weenie.net/projects/plugins/exception_logger/lib/logged_exceptions_helper.rb
I could also write a helper for AJAX paginating links for paginating_find...
Wouldn't mind seeing how these two plugins stack up with each other.
I found an Ajax approach here that lets you "sort, search and paginate"
http://dev.nozav.org/ajaxtable/?sort=name
Is it wrong that I was giddy like a small child on Christmas day when I saw the new Railscast in my iTunes Podcasts directory? Thanks for all your awesome work on these podcasts!
Hi, I'm the main maintainer for the will_paginate plugin. Ryan, thanks a lot for this screencast! For the rest of you, you can get familiar with the plugin by generating the RDoc documentation; simply type "rake rdoc" while in the plugin directory.
If you want to report bugs or suggest features for this plugin, go to http://err.lighthouseapp.com/projects/466-plugins. Thanks!
That good ep. I wish you create episode about testing on rails. Thaink you
@lisa, with UJS it'd extremely simple to layer ajax pagination on top of will_paginate. Check out ujs4rails.com :)
thanks for pointing the way to will_paginate. however, i was trying to implement it to paginate "entries" that works with the "acts_as_taggable" plugin. i placed this in the entry model.
def self.taggedwith(tag, page)
paginate :conditions => ["tags.name=?",tag],
:joins => "INNER JOIN taggings ON entries.id = taggings.taggable_id INNER JOIN tags ON taggings.tag_id = tags.id",
:order=>"entries.created_at DESC",
:per_page => 10,
:page => page
end
while i do get the correct entries, the tag_list are always incorrect. could you suggest any workaround?
Great screencast as usual. I have learned so much from your podcasts that my rails abilities have improved considerably.
Unfortunately, the will_paginate plugin won't work with my version of rails (1.2.3). I'm not able to start mongrel, as I get "finder.rb:11:in `included': undefined method `alias_method_chain'". Shame as I really want to use it for an artists website that I'm redesigning.
Thanks again, Ryan. You are the man.
@Markus,
I've pointed out the link to submit bug reports to in my previous comment. And the error you're seeing *can't* be right because Rails 1.2 uses alias_method_chain internally all over the place! If you keep seeing the error, submit a proper report with more information. Thanks
I'm having trouble installing the will_paginate plugin using <code>script/plugin install svn://errtheblog.com/svn/plugins/classic_pagination</code>.
I keep getting a timeout error saying subversion can't connect to host 'errtheblog.com'. Anyone have any ideas? Is anyone else having this problem?
Thanks Ryan, this is the only thing I needed when I decided to move to the edge Rails!
Just a curiosity question: What the scaffolding in rails 2.0 will generate to paginate pages?
@Mahmoud, the scaffolding in edge Rails uses what is currently called scaffold_resource. This doesn't do any pagination.
That does mean a default RESTful design of applications ??
@Mahmoud, yep. The default scaffolding will be RESTful in Rails 2.0.
Great screencast, thanks a lot.
I'm using the will_paginate plugin myself for a while now and I really like it. However I've come across some problems while trying to paginate special queries (e.g. custom finder class-methods on your model). I've put up a summary in <a href="http://zargony.com/2007/07/21/paginating-special-queries/>this post in my blog</a>.
If I was gay I'd definitly would want to be your boyfriend!!!! Your casts are so seeeexy! For real!!!
THAT was gay ;)
I'm getting no response at all when attempting to install from this address...
svn://errtheblog.com/svn/plugins/will_paginate
Could there be a problem in Windows? I don't seem to have this problem with any other plugins?
@bilson, it's working for me. Is it still not working for you? Maybe Windows doesn't like the "svn" protocol. Not sure what the solution is.
My mistake. It is working now. I thought I could download via svn from the command line, but I have to do so directly through the Tortoise interface instead.
Great screencast. Great plugin.
你说中国话谁看的懂啊,sb啊
rails2。0早着呢
.. ... .
Hello,everybody!
to bbb:
其他人是看不懂中国话,不过还有你这个sb可以看得懂啊。
Mislav,
I modified view_helpers.rb to add clean and simple ajax support.
Look here http://batmanrails.blogspot.com/2007/10/ajax-support-for-willpaginate.html
-Batman
你說中国話,我說中國話...
@Ryan Bates,
Install will_paginate with svn:// not work to me too. After I install SVN command line this work
Hey,
I really need to get this thing to work wiht ajax, i need a link to remote to update a specific id and I can't get any info on how to do that...plus I am not very good with rails...can someone help out with this?
Ajaxify will_paginate
instruction left by @The Batman are outdated (already!). Err, or whomever maintains will_paginate, really needs to add Ajax support. Without this plugin is not "game-day" ready.
I hacked up a version that works for me but it's not publishable.
I would look for another paginator that supports Ajax before using this one.
Hello, I have will_paginate working with lowpro. It does ajax pagination just fine. Except that I have two partials in the same view, and I cannot figure out how to make each work separately. The first page renders fine, because each partial draws from a separate instance variable in the controller. But when you click on another page for each partial, each partial sends the same exact message to the controller. Each partial says "give me page two for this view", rather than "give me page two for this partial". Any hints?
this videocast was extremely helpful to me, thank you for your hard work.
Charles, try:
http://railsontherun.com/2007/9/27/ajax-pagination-in-less-than-5-minutes
If I have 100 pages how do I display pages 1 through 5 then .... and the last 5, 95 through 100?
Would anyone know how to use this in conjunction with form parameters? I have a form, the parameters of which go into my find / paginate function. This works fine for the first results page, but when a link is followed to subsequent pages, the search parameters are lost. Is there a way to pass a parameters hash via the will_paginate helper method in the view???
The problem is explained in more detail here:
http://www.railsforum.com/viewtopic.php?id=14604
@Ned, will_paginate should automatically pass the params. Make sure to use GET request in your search form along with the helper methods which end in "_tag" (such as "text_field_tag" and "check_box_tag"). See this episode for details:
http://railscasts.com/episodes/37
Thanks for the reply Ryan - I'll check this out when I get the chance - I think I might be using different form helper methods, which might explain why the parameters aren't passed...
Thank you for this video.
I am having a problem displaying my data in the view side, I am using partials.
<%= will_paginate @my_object %>
and I only see the pagination links on the browser but I can't see the data, although when I try to loop through @my_object without using will_paginate I was able to get the data, I don't know what I am doing wrong I followed the same steps from this screencast.
@samani ismael
Hi, the method will_paginate doesn't display the data, only handles the paging.
<% for object in @my_object do %>
<%= object.id %>
<% end %>
<%= will_paginate @my_object %>
Is it here or the repository for will_paginate is down ?
How can we pass get parameters when user navigates to enother pages using will_paginate?
the repository seems to be down
http://require.errtheblog.com/ -> moving servers. be back soon.
:(
I'm assuming that there's no option for ASC/DESC ordering is there?
ie: :sort_order => 'ASC'
Hey Ryan, great screencasts. I've learnt 99% of my Rails from them :)
I have a question though...looking at my logs, it looks like the SQL generated uses 'like' everytime since the :conditions is used. Doesn't this take a very small performance hit?
What would be the best way to exclude the 'like' search except when a search term is passed? Use a condition to check if the 'search' parameter exists and then append it to the paginate code?
Thanks.
Keep up the great work.
Hi, Thanks for the very informative episode
Now we are facing problem with the new will_paginate in rails 2. Can you make a screencast for us on how to use it because we keep getting errors
Thanks
hey ryan! i'm trying this out today. it looks great in your tutorial! so hopefully it'll work for me.
noticed that the installer changed too, after the plugin just refused to get itself installed. please be advised :)
http://errtheblog.com/posts/56-im-paginating-again
Hi Ryan, I was wondering, what do you use to generate the 'Previous' and 'Next' links that we see above?
Thanks in advance,
-Conrad
This screencast was very useful. Thank you for doing this!
please let me know how can i use will_paginate with alphabets. i.e i have a dictionary with words from A to Z. so i would like to paginate A, B, C, .., Z as pages and clicking A for instance will show all words start with alphabet A. kindly let me know. many thanks in advance.
Thanks Ryan for this screencast.
I have created a blog entry on how to ajaxify will_paginate thanks to lowpro:
http://hasnosorrow.wordpress.com/2008/10/13/ajaxify-wil_paginate-with-lowpro/
Hope that helps,
Guillaume
Very, very helpful. Thanks for your time and effort with this. You are a great instructor.
-Louis
Is there any way to get on the view what is the amount of objects I want to display per page? Thanks!
Hey ryan, is there a good way to modify the will_paginate helper if you want to page or action cache the pagination.
rails envy had a tutorial on adding to the routes.rb the necessary route and what the new pagination link should look like, but is there a way to do that automacially in the view?
Hey, great blog, lots of useful stuff. I'm a bit of an RoR noob and this site has helped my out a lot. Is a there a simple way to build in a flash message for when the search results come up with nothing?
--Thanks a bunch
Hi Ryan!
I really love your screencasts and I will definitely donate some bucks to you :-)
One thing you could update is the source to the plugin. They are now on github and the maintainers strongly advise not to use the deprecated svn-repo :)
URL:
http://github.com/mislav/will_paginate/tree/master
KR tschundeee
i am very much new to rails.This gave me a very good idea.Thank u. please post good tutorials from scratch so that it gives a fair idea for us.
Love your screencasts.
This is my first contribution to the RoR community, so I hope it is a help.
I searched a long time for a solution, until I discovered it was right there in will_paginate.
paginate_by_parent_id nil, ...
made it possible to add an extra edge to my finds, so that the search is only for posts that do not have a parent_id.
Could not make this work with :conditions alone.
Here is the code from my model post.rb:
def self.search_list(search, page)
paginate_by_parent_id nil,
:per_page => 5, :page => page,
:conditions => ['title like ? or body like ?',"%#{search}%","%#{search}%"],
:order => 'created_at DESC'
end
Hi guys,
For Ajax Pagination visit my blogpost.
http://pulkitonrails.wordpress.com/2009/04/24/ajax-pagination/
Ryan how can stop this
THISSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
Hi, the svn server in no working, can you bring an alternative?
Really a Nice Screencast. Just a quick doubt,
When using will_paginate is it necessary that we should keep our search parameter in session?
for example
view
<input type="text" name="q">
method
@product = Product.paginate(:all, :conditions=>["name LIKE ?", "%#{params[:q]}%"], :page=>params[:page], :per_page=>10)
it is giving me those results which are not matched with the criteria, when I am scrolling through pages.. any help?
very great tutorial.It is really useful for fresher.It would be great if you add Ajax functionality with pagination.Looking forward for your reply.
I want an example with will_paginate,Ajax with out using JQuery.
great!!!(:
ruby script/plugin install svn://errtheblog.com/svn/plugins/will_paginate
not working
use ruby script/plugin install http://github.com/mislav/will_paginate.git
Hey Ryan. Great work! Can i ask u a question though , kinda stupid actually. But i was wondering how to combine will_paginate and searchlogic? if u could help me out that'll be great..
Nice one ryan,
It's great that you would help out everyone like this.
This is working great for me! My only problem is that I'm using the :page_links => false. It's working correctly by taking out the numbered links and only displaying Prev and Next for the links.
But those two links are on separate lines. Prev is on one and Next is on the next line in the browser. I tried using :style => 'display: inline' so that they would be on the same line, but it's not working.
I'm sure I'm messing this up somewhere. Anyone else having the same issue?
thanks for post. nice.
nice
Nice. Do you think you could add how to dynamically change the number of records shown per "page"?
Clearly saying thank you is not going to just be sufficient, for that amazing lucidity as part of your writing content articles. I will swiftly consider maintain of your rss feed to remain abreast of any updates.Genuine work and considerably becoming effective within your efforts and world wide web enterprise tries.Regardless protect up the helpful purpose.Thanks.
I recommend jumping over
rất hay
This episode has been updated for Rails 5 as a blog post. Will Paginate in Rails 5