Update: The source and install instructions are now located at: http://github.com/mislav/will_paginate
We’ve all been paginating for a few months now with will_paginate because it’s such a sweet plugin, but Koz put a call out on Rails Core wondering what the leading pagination plugins are. Somebody tell him to subscribe to Err already.
Pagination is getting tossed out of Rails 2.0, so what better time to define the leader. The first step is to pluginize the classic pagination currently in Rails. That’s kinda boring, so we moved straight away to step two, had Mislav Marohnic merge his will_paginate rewrite into our code base, and slapped a 2.0 label on it. (We’ll eventually do step one, but bear with us)
It’s a major release, because we broke the existing API. Mislav’s rewrite converted the paginate method to return not an array of objects and the current page, but a PaginatedCollection proxy. All that really means is you have less code to write now, but you should update any existing code if you’d like to upgrade.
Here’s the updated way to use the plugin via the README:
app/controllers/posts_controller.rb@posts = Post.paginate :page => params[:page]app/views/posts/index.html.erb
<p>Handful of posts coming up</p> <%= render :partial => 'post', :collection => @posts %> <p>Now let's render us some pagination!</p> <%= will_paginate @posts %>
The really slick thing going on in the background is that unless you explicitly pass in total_entries, the paginate method with automatically grab the total count based upon the conditions you’ve specified. Nice.
As always, grab the plugin here: ./script/plugin install \ svn://errtheblog.com/svn/plugins/will_paginate
I really like this plugin
http://svn.cardboardrocket.com/paginating_find
It extends find() and makes it really transparent
Will_paginate looks like a sweet plugin, however, I am getting an undefined method ‘paginate’ error when I made the call to paginate, I am sure it is something simple. Any help will be much appreciated.
Bob, looks like the plugin didn’t install properly for you. Make sure it is in the “vendor/plugins/will_paginate” dir and that it’s fully checked out. Otherwise, file a bug on Lighthouse.
DODH! Never mind, i forgot to restart webrick after installing the plugin, I don’t see that error anymore, thanks and sorry for the confusion.
I totally subscribe already man :)
I liked this one: http://codefluency.com/2007/3/27/paginator
I personally like http://paginator.rubyforge.org/
I second the paginator gem. It’s not as elegant as will_paginate, but it deals equally well with normal finds, find_by_sql and so on.
The beauty of will_paginate is that you can use it however you want. You can use it via find_by_sql and things of that nature, or you can use all of the sugar it provides.
PJ, my concern is that I’d like to use eg. paginate_by_sql whereas will_paginate relies on the query being a parametrized Rails find with :order, :joins and so forth.
I should probably try and adapt my complex queries.
Is it just me being daft or does this break if you try and use :order with it? (on postgresql this gives errors about a missing GROUP BY clause when running the count(*) SQL)
Change line 26 of finder.rb to read “count_options = options.slice :conditions, :joins, :include, :group, :distinct” and it seems to work with :order
I haven’t tested this extensively.
Here’s a hack to get will_paginate and acts_as_taggable pluggins to play nice with each other, drop this code somewhere in lib:
With this in place you can now call stuff like:
You have to manually pass in the total_entries, but hacking the code where total_entries is set in the will_paginate finder method could get around this.
Does anyone know of a pagination helper (this one or any other) that will allow me to find which page a given entity is on?
So for example, if I have a list of 100 items with 20 per page, and the list is sorted by duedate, and I add a new item and I want change the page to the correct one to show the added item.
I have done it with brute force so far (just creating sorted list, determining element location then dividing by # per page) but this this seems like a waste
Here’s how I paginate the related parents of children. Anyone have a better way?
How about paginating a collection that you build from multiple finds because the result set is too complex for a single query?
Is there a way to paginate an already existing collection?
Paginating an existing collection would reduce the performance boost you’d get from paging in the first place. The key to paging is ultimately tacking a “LIMIT x, y” on to the end of your sql statement, which reduces the amount of records returned. That being said you might be able to hack the finder.rb code to pass in a collection and then just trim the array down in code.
Does anyone know of a pagination helper (this one or any other) that will allow me to find which page a given entity is on?
This paginator was a great help and worked as advertised with one caveat. My site is a search engine that makes heavy use of multi-dimensional queries in params. Since url_for is not able to translate multi-dimensional hashes from params into a proper query string in the view, I made the following tweak to the view_helpers.rb code, which now enables the helper to work (at least on my site) with any depth hash in params. Not sure if this is a general purpose solution – comments?
Below for modification:
Nice work but after trialing this and http://svn.cardboardrocket.com/paginating_find it was the paginating find that came out on top for me. I think its the real minimalist way to add paging and it works seamlessly on any find including on associations which I find myself paging a great deal.
Modification to the comment above: if you have multi-dimensional queries in params, the following tweak to the view_helpers.rb code works for me. I noticed a case where the initially submitted code didn’t work, so here’s the new, improved version:
replace the line link_to text, params.merge(:page => (page != 1 ? page : nil)
with
if request.request_uri.match(/page=\d+$/) link_to text, request.request_uri.sub(/page=\d+$/, “page=#{page}”) else # the initial request case has no page number to replace if request.request_uri.match(/\?/).nil? then link_to text, request.request_uri + ”?page=#{page}” else link_to text, request.request_uri + “&page=#{page}” end end
Nice plugin guys, and nice blog, too. One little niggle: you broke ActiveRecord::Base.respond_to?. Try this in place of your code:
Is anyone having problems using this in edge rails, seems to be adding the ?page=2 to the title bar, but not fetching the right results
using thiscode @blogs = Blog.paginate(:all, :per_page => 3)
Mark: Try dropping the :all. It is implicit.
Blog.paginate(:per_page => 3
I got will_paginate working with acts_as_solr. Thanks for a well-written plugin!
Hrm, seems your comment system strips URLs. Try this: henrik.nyh.se/2007/06/using-will_paginate-with-acts_as_solr
Incidentally, you “So-and-so-many people have commented” count is inaccurate, since it actually counts number of comments, not number of commenters as claimed. ;)
Henrik: Ha, nice catch! We may have to change the language or update the counter for the comments. Incidentally, our blog doesn’t swallow URLs, there was just some typo’d textile in that comment. I’ve fixed it.
API change broke my web site :( crap
Nice plugin, very pretty code.
I made some changes however, to allow me to use multiple paginated lists on one page.
I use to move all my finders into the model. How do i do this with the paginate method?
I get this error:Ok, I figured this out. I just had to pass the params in the controller to the method in the model.
But now the will_paginate helper in the view throws an error:But I don’t find page_count anywhere in the README. :confused:
Nevermind. Everything works now. Ty for this nice plugin! :)
First off, great plugin design!
Second, is anyone else getting a “stack level too deep” error. The method_missing_with_paginate method is getting into an infinite loop on Rails revision 7064.
Can’t connect to host, both today and yesterday.
Giles: Really? What IP are you trying to hit?
http://pastie.caboo.se/72532
can’t connect to host. Tried two days ago and today. Same result.
Can I use this if I want to paginate across a collection that’s returned by Product::past? I have a lot of class methods that find a set of objects in my models and I’d like to use those—instead of having a bunch of find conditions specified in the controller.
Hi, I’ve had a problem connecting to your repository also and finally realized that the port used by svn protocol by default (3690) was simply blocked by local nat/firewall. So probably guys who can’t connect experience the same trouble :)
Nifty little plugin. i use this alot in my app. thanks.
It seems we have a bug here. Using this code:
where conditions is condition array ([“blah=?”, 123]) makes will_paginate go crazy by not including message_box_id condition on count and resulting way more pages than there should be.
The development log:How do you use eager loading with will_paginate and acts as ferret.
paginate_by_contents works great except it seems to ignore finder options such as :include, :order, :joins, :conditions, etc.
Any advice? Thanks.
If anyone uses the scoped_out plugin I wrote up a little post on how to get it to work with will_paginate.
Any chance you can wrap up a latest gzipped package for those of us behind a corporate firewall? It’d help greatly :)
C:\rails\parking>ruby script/plugin install \svn://errtheblog.com/svn/plugins/wi ll_paginate
no instala el plugins
If is a machine on the internet which has a clear view to errtheblog:3690 and on which you have account :
$ ssh -f -L 8910:errtheblog.com:3690 -N@
$ ./script/plugin install http://localhost:8910/svn/plugins/will_paginate
Really nice plugin, but I’m having problems tonight using it on a model. The collection returned by paginate/paginate_all_by_whatever in my controller is 3 items, but the page_count() method returns 1, so the pagination options never render. I haven’t looked too deeply into it yet, but are there any known conflicts with attachment_fu?
This is a sweet plugin, Thank you so much :) Subscribed!
Am I being daft or is it just me who can’t install this plugin? I can browse the repository with my TortioseSVN-browser, but running “ruby script/plugin install vn://errtheblog.com/svn/plugins/will_paginate” won’t make any thing at all. Help, please!
Hi,
I made a slight modification to will_paginate() to support Ajax. How do I submit my change to you?
I blogged about how I got acts_as_taggable to paginate with will_paginate, without hacking either…
http://blog.wolfman.com/articles/2007/07/30/paginating-acts_as_taggable-with-will_paginate
There is a need to paginate an existing collection. Yes, this may seem pointless for performance reasons as was pointed out way above by Nathan.
However, there are cases where data has to be sorted on the app side, not the database. For example in some cases when using the GeoKit plugin. Because it is mostly incompatible with :include, you have to grab all results and then do a sort_by on the app side. I would then like to paginate these sorted objects.
I think this was mentioned before, but you can easily paginate a collection using the Paginator gem with will_paginate like this…
Thanks for the help Jim, but your code doesn’t work.
The top section needs three parameters for Paginator:
The last section doesn’t work at all… pager.page(page).items doesn’t seem to make sense. I’m not sure the “replace” method is valid either? Judging by the rails docs I don’t think this is the method you are looking for.
I guess this is off-the-top-of-the-head code. I’m trying to get it to work but not sure exactly what’s going on here. Thanks…
Whoops, never mind last comment (and sorry for the formatting goof). Just realized the paginator gem differs from the Paginator stuff that comes with Rails 1.x. That’s confusing!
Yea Sorry I should have been more explicit that you need to install the Paginator Gem, other than that the code I posted above should work fine, as I use it in a number of places.
Actually I modified your example to work with the Rails paginator:
Nice plugin. The customization of the actual HTML is a bit lacking. I added this to view_helpers.rb @ around line 80.
It shows the total number of items and the items that are currently being displayed.
there is no plugin!!! errtheblog.com/svn/plugins/will_paginate generate error
If I want to handle all the communication with the db for batching myself, but I want the keen view code for the dig-style boxes… can will_paginate help me?
http://errtheblog.com/svn/plugins/will_paginate still there is only ‘OH SHIT’ there, any alternative link?
Hi, I’m behind my companys firewall and couldn’t reach your SVN repository through svn://. Is there a way to access your SVN repository by using HTTP?
I see that will_paginate tries to preserve params. Unfortunately if fails if the params weren’t flat. So it will turn “tool_category”=>{“id”=>”2”} into “tool_category”=>”id2”. I suppose this is an “undocumented feature” ;)
http://pastie.caboo.se/86477
Here’s my code for the de-method_missinged :paginate method. This can make your RSpecs run a little cleaner if you need it.
Maybe I’m just stupid.
OK, so I’m just stupid and noobly.
But for some reason, when I apply the code, I get nothing output. Squat. Zip. Zero. I know that values are returned, as they’re returned when I run in the console.
Here’s my view file:
Listing Bulletins
<% for bulletin in @bulletins -%>- Render `bulletin` in some nice way.
<% end -%>
Now let’s render us some pagination!
<%= will_paginate @bulletins %><%= link_to ‘New bulletin’, :action => ‘new’ %>
Here’s the HTML output:
<!DOCTYPE html PUBLIC ”-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
Listing Bulletins
Now let’s render us some pagination!
New bulletin
Any help?
~Mark
After we installed this plugin, we started having problems with our yaml fixtures. It had problems parsing fixtures that contained erb code, it thought it had tabs instead of spaces. After removing the plugin, it worked fine again
Hi, thanks for the great plugin! just a short question..
There are patches for Ajax and Multiple Collections per Page, is there any reason to not integrate them into the basic plugin?
Otherwise they get outdated, can’t be applied, and someone has to write a new one ..
I may have found a way to work with existing collections:
Instead of this which doesn’t work:
...do this:
|| 1), 20)Can anybody confirm this is robust? Is there a better way?
I’m currently working on a three tier app that uses ActiveResource in the view tier, rather than ActiveRecord. I tried simply mixing in WillPaginage::Finder into ActiveResource::Base like the init does for ActiveRecord::Base, but alas there appear to be quite a few assumptions that it really is ActiveRecord (such as with_scope).
Any chance for some pagination love for ActiveResource as well?
Hi, had a problem for with page_link_or_span due to the fact that my search params that I’m using are not flat, so I came up with this which I put into application helper, and this worked for my search results, I use will_paginate for everything else.
def my_page_link_or_span(page, span_class, text, param) unless page content_tag :span, text, :class => span_class else html = ”<a href=’/properties/search?page=#{page}” if params[:search] params[:search].each do |key, value| html << “&search%5B#{key}%5D=#{value}” end end html << ”’‘>#{text}” end end
it’s a bit like cracking a nut with as hammer but I’m new to Rails.
I have extended the will_paginate to support custom block-based pagination. Here’s the patch:http://www.arturaz.net/blog/i-am-half-a-robot/extending-will_paginate-to-support-block-style-usage/
This is nice, I was looking for something like this. Very simple and easy to use.
I install Exported revision 365, it seems repeat the same conditions:
paginate_options = { :page => params[:page], :per_page => 30, :order => ‘ID DESC’ } @project = Project.find(params[:id]) @project.tasks.paginate paginate_options
=> SELECT count(*) AS count_all FROM tasks WHERE (tasks.project_id = 5) AND (tasks.project_id = 5)
anyone met the same problem?
I created an association extension so that I can call @post.comments.page(params[:page]||1), all the page method does is call paginate. It works fine except I have an extra database call select * comments before the paginate selects, any idea why this would happen?
thanks for the plugin
For some info on: *paginating using ajax *paginating ferret search result.
http://EmmanuelOga.blogspot.com
P.S.: I’m curious why haven’t this quite nice patch been added to will_paginate. It works pretty good!:
http://err.lighthouseapp.com/projects/466/tickets/67-will-paginate-patch-ajax-support
Sorry, here is the link:
two very useful pieces of code related to will_paginate and acts_as_ferret
Hi,When I try to install the plugin I get an error that connection could not be made because the target machine actively refused it. Could you please help me with this… I even turned off my firewall but its not working…
I just installed will_paginate today. It didn’t work for me until I made the modification proposed by Logan.
I suggest this change be committed.
Reading through the posts, one can sense a desire for will_paginate to handle collections. I myself would love it if it could handle arrays. I extended a ‘has_many’ association by adding a method defined in a block passed to the association. This method contains complex SQL that I could not fit into normal “Rails way” calls. But this construct returns an array, so I can’t use it with will_paginate – which really mucks up the view for this model as compared to all my others which can use will_paginate.
Here is the reason for not supporting collections (from a previous post):
=============================== Paginating an existing collection would reduce the performance boost you’d get from paging in the first place. That being said you might be able to hack the finder.rb code to pass in a collection and then just trim the array down in code.
Don’t get me wrong: I really appreciate making this paginator available to the masses. However, regardless of your reasons for not doing so, many would like the ability to work with collections. Instead of having each of us “hack the finder.rb code” are there any plans by the keepers of the plugin to add this support?
Oops. Sorry about the large bold text in the previous post. I didn’t realize that a bunch of equal signs would cause Textile to generate that effect.
Seems like a nice feature to include in will_paginate by the way, very useful to jump to the page with the last updated item on it.
To support ajax in will_paginate I modified view_helpers.rb in the plugin.
Examples to work with ajax: <%= will_paginate @collection,{:remote => true} %>
If you need to pre-determine the url for the ajax: <%= will_paginate @collection,{:remote => true,:url=>{:controller => ‘xxx’,:action => ‘yyy’}} %>
module WillPaginate # = Global options for pagination helpers # # Options for pagination helpers are optional and get their default values from the # WillPaginate::ViewHelpers.pagination_options hash. You can write to this hash to # override default options on the global level: # # WillPaginate::ViewHelpers.pagination_options[:prev_label] = ‘Previous page’ # # By putting this into your environment.rb you can easily localize link texts to previous # and next pages, as well as override some other defaults to your liking. end
if total_pages > 1 remote = false if options[:remote] remote = options[:remote] end base_url = {} if options[:url] base_url = options.delete(:url) end end
options = options.symbolize_keys.reverse_merge(pagination_options) page, param = entries.current_page, options.delete(:param_name) inner_window, outer_window = options.delete(:inner_window).to_i, options.delete(:outer_window).to_i min = page – inner_window max = page + inner_windowAhhh… last post was a mess. I will try again:
To support ajax in will_paginate I modified view_helpers.rb in the plugin.
Examples to work with ajax: <%= will_paginate @collection,{:remote => true} %>
If you need to pre-determine the url for the ajax: <%= will_paginate @collection,{:remote => true,:url=>{:controller => ‘xxx’,:action => ‘yyy’}} %>
Change the following in view_helpers.rb:
options = options.symbolize_keys.reverse_merge(pagination_options) page, param = entries.current_page, options.delete(:param_name) inner_window, outer_window = options.delete(:inner_window).to_i, options.delete(:outer_window).to_i min = page – inner_window max = page + inner_windowDamn.. cant post the damn thing. Please delete my comments :-(
Ok, I put the example for ajax support here:
http://batmanrails.blogspot.com/2007/10/ajax-support-for-willpaginate.html
Why is it so popular to show the amount of time that’s elapsed between when a post was made and when a comment was made?
Has that ever helped anyone? The original post doesn’t even appear to be dated, so why would I care that Yoni added his comment four months later?
I like the addition of the link_to_remote to will_paginate. It’s exactly the addition I was looking for. To the developer/maintainer: do you intend to officially add this support? Would be nice.
Awesome stuff. Is it somehow possible you provide a repository accessible via HTTP? The SVN ports are locked out by a firewall in some places. Would be great. Thanks.
mhlk,,hcxbhxgybtwhrkgbth5jytbr6khry7jkhlreot,ghmuljkhmukiljyumkljymuklijmsdfrtkghmnbjnhm.ljum.,gmlgfm bjnrtf,kvcmjlbncjhnfjkbgfnyjhncx fdvxvcbvhjgbgfdghmbfhdfc dnsfvcxvdf ncvgmdsjvhdngfhbthjgkuhuyrehtgyuhytnjhbnm,sadwnkldjrtljihrkuigybhnjtrkuyvchn fmbh ntmhgbthyjygyigth5juk,yth6uit7y6hu76hu6uiyhui7yu7uhy6huyhy5h6uk
For some reasons, I have to paginate to models, which I would like to merge and display together on one page.
So I do
m1 = Model1.paginate…
m2 = Model2.paginate…
How can I merge m1 and m2 ? I tried m1 + m2, but this changes the class to an array (and <%=will_paginate=> won’t work anymore…
thanks.
Hi, this is a very nice plugin, but I have a question.
How can i make work will_paginate with a find_by_sql() call ??
regards!
oh! I found that will_paginate has paginte_by_sql support, an example, thanks for this very nice pluggin
@records = MyModel.paginate_by_sql(“SELECT …. JOIN on.. COUNT..ORDER BY … ... ”,:per_page=>20, :page => params[:page])
regards!
Well, here’s a dilemma.. I’m creating a WillPaginate collection as normal with @object.paginate :page => params[:page], :per_page => 10 and then using certain criteria to remove elements from the collection with @collection.delete_if { |c| block }.
The problem is that after removing elements, some pages are displaying 5 results, others 3, some pages are showing no results…
Is there a way to reset the index after using the delete_if method on the collection?
Thanks, Josh
how to use it with acts_as_taggable_redux? who can help me?
will_paginate is not getting installed am running normal install with the path given by you,after i install i dont see that in vendor/plugins
Larry and Jason, Here is a controller method I cooked up to paginate an already found collection. As has been mentioned, it’s suboptimal to do this after the SQL query… but ya’ know, sometimes it just comes in handy for a clean and simple solution. My search action is polymorphic and has a big case statement.. and each model has its own encapsulated finder methods that don’t play well with standard paginate methods.
When using paginate_by_sql it was not stripping out my ORDER BY clause in the COUNT() version of my query. In my case, the ORDER BY clause adds a lot of overheard and its not needed to get a generic count.
I have patched finder.rb and added in the ability to strip out the ORDER BY clause for the COUNT() query. The patch is here:
http://blog.ruckusing.com/wp-content/uploads/diff/will_paginate.diff.txt
The actual regex might need to be modified, it might be too liberal. Its a start though.
Hello, again a nice plugin from you guys, just one thing I’ve noticed but I’m not experienced enough to correct it [ if there’s something to correct ]: According to the ActiveRecord documentation, when I use find with :joins the obtained data comes read only by default, so to override this you must pass :readonly => false. This is not a problem with will_paginate if the results of the query fit in one single page, but as soon as it has to paginate I get an error saying Unknown key(s): readonly.
I’m apologize if it’s something that has nothing to do with will_paginate and thanks in advance for any ideas to solve this.
hi, i have installed the plugin.well ist works! But how can i use a order_by like this in the old pagination of rails: @entry_pages, @entries = paginate :entries, :conditions => conditions, :order_by => sort, :per_page => 20
this: doesn’t work @entries = Entry.paginate :page => params[:page], :conditions => conditions, :order_by => sort
—--employees_controller.rb: class EmployeesController < ApplicationController # GET /employees # GET /employees.xml def index @employees = Employee.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @employees } end end ... end—-—-—— employees_helper.rb: module EmployeesHelper end—-—-—-—-—- models/employee.rb: class Employee < ActiveRecord::Base end—-—-—-—-——-Listing employees
<%= link_to ‘New employee’, new_employee_path %>
i try to install this plugin more times,but every time i install using ‘ruby script/plugin svn…’,no response appeared,why?
I think you have to do this first: Download http://subversion.tigris.org/files/documents/15/39559/svn-1.4.5-setup.exe and install it.
Can anyone tell me how to post “nice looking” listings on this site. The previous listings I posted don’t look good.
Nothing happens when I run the install. Look: C:\rails_projects\photos>ruby script/plugin install svn://errtheblog.com/svn/plu gins/will_paginate
C:\rails_projects\photos>ruby script/plugin install svn://errtheblog.com/svn/plu gins/will_paginate
HELP!
Hey for anybody else having problems installing the plugin, you need to install SVN first!
the plugin is great, i already use a lot, the question is hi, it’s possible to use will_paginate with a :group => condition ? like with :order => sort help in advance…!!
Very nice plug-in. Works like a charm, thanks a lot.
pagination displays well for me. However when I click page 2 link, I expect
http://localhost:3000/post?page=2
However the link is actually like below.
http://localhost:3000/?page=2
What could be wrong? I am using Rails 2.02
I’ve been getting exceptions lately because of SQL generated from will_paginate when a bad page parameter (a URL instead of a number) is used. These are presumably from bots looking for servers to compromise. This causes the following error:
A ActiveRecord::StatementInvalid occurred in controller#show:
Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘-12, 12’ at line 1: SELECT * FROM data ORDER BY created_at DESC LIMIT -12, 12
Should I be sanitizing the page parameter on my end or should it be done by will_paginate? The sample code in this post (@posts = Post.paginate :page => params[:page]) indicates that will_paginate will deal with it.
Thanks!
Ah, just read the Christmas update…glad the page number thing is fixed.
This plugin is great! I like it very much.
HELLO??? Is anyone reading these messages? Three people have asked for a version accessible from behind a firewall and there has been no effort made, as far as I can tell, to provide it. I’m excited about Ruby and Rails, but if I can’t even get basic plugins installed, my support will be lost along with that of many other potential corporate allies. Getting IT to open a port on the firewall is next to impossible. Please, Err-folk, provide an HTTP-based way to download! We old-school corporate folk may be a pain initially, but once you earn our support, you have it for life…
At the top of the page it says: “Here’s the updated way to use the plugin via the README:” But clicking on the “README” link produces a “404 Not Found Error”. Which kinda sucks, seeing as how that contains the instructions for using the plugin. Can someone please fix the link?
A belated “thank you!” to David Lowenfels for your post (at the “6 months later” mark) about paginating collections. It’s belated ‘cause I just now returned to the site and saw it.
Anyway, thanks for taking the time, David!
Hello, I’m trying to use will_paginate but I have a issue. Since the pagination is into a sliding panel (made with Spry) I need to pass it the active panel. I mean the url must be mysite.com/admin/settings?panel=1&page=2 instead mysite.com/admin/settings?page=2
Is it possible ??? I tried to add the panel value directly but it doesn’t work.
Thanks
How do i modify the generated controller and action?
I was assuming something like the following, but doesn’t work.
<%= will_paginate @posts, :controller => “new_controller”, :action => “new_action” %>
It’s pretty annoying that the link to the README is broken. And the article is missing install instructions for newbies. However, I did find this link: http://rock.errtheblog.com/will_paginate I hope it’s the right one.
+1 for paginating_find from Cardboard Rocket.
I modified finders.rb to allows you to pass params to paginate_by_sql in the sql arg, and generate an sql statement for you. You can also pass :table to specify what table u want to use, if left blank it will default to the table with the controllers name. You can also pass :excludes as an array or columns u want to exclude from the search (e.g. if you pass :excludes[‘size’, ‘title’] as an argument it will remove :size and :title from the params hash befor it generates the sql query). Controller, Action, and Page are removed by default.
I also added this to core_ext.rb to help in converting the params hash to sql query.If anyone can improve on this feel free, and please post what u come up with… this is a feature that i would like to see made a standard part of will_paginate
Has anyone been able to come up with a fix for passing parameters to the will_paginate call in the view? I’m trying to use will_paginate to display the results of a search, the parameters of which are gathered through a form. The first page of results is shown, but the parameters hash is not passed on to any of the subsequent calls (see http://www.railsforum.com/viewtopic.php?pid=55691 for more details of this problem).
How does will_paginate work with Ambitious ActiveRecord?
UP!!!!
UP!!
Hello, I’m trying to use will_paginate but I have a issue. Since the pagination is into a sliding panel I need to pass it the active panel. I mean the url must be mysite.com/admin/settings?panel=1&page=2 instead mysite.com/admin/settings?page=2
Is it possible ??? I tried to add the panel value directly but it doesn’t work.
Thanks
Yes, I like this one!!
good!!
Excellent plug-in. Thank you!
If you have “unknown method exception” just try to reboot your server. It helped me.
i’m trying to find out how to get the row/object count for a given paginate call. also, how can i access the first object in a collection?
@found = paginate(...options..)
found_items = @found.size/count/length ????
id_of_first_item = @found.first.id /[0].id ???
Great plugin! Does this 2.0 version of will_paginate supports act_as_ferret ?
Hi! I need some help to install the plugin. It doesnt work for me, still got the error mesage, after hours of work! How do I install it? When I create a new RoR project (rails project) then after that I install it in that directory? Then it is in vendor/plugins/will_pagina. I after that create a modell, and a controller. Then it Should work, right? But not for me. an somebody please help me? “undefined method `paginate’” Error message. I installd the scaffold plugin before installing pagina plugin. THANKS!
Hi!
I just noticed that has_many :through is somehow broken when will_paginate is installed and enabled in rails rev9125. To be more precise, the AssociationCollection#any? method falls into infinite recursion yielding a StackLevelTooDeepError.
I’m currently using rails rev9215 and it seems to me that maybe rev9199 introduced this behavior. I’m not entirely sure wether it was exactly rev9199, although it seems to be the only changeset related to associations in the near past, my app was definitely working yesterday :) Also, my app is working fine with will_paginate on rev9199!
I love edgerails! I don’t want to freeze because of this issue, however fixing it myself is beyond my method_missing fu and general rails code knowledge and would take me time I currently simply can’t spend :(
Any help very much appreciated! cheers Martin Gamsjaeger
Hi, Martin.
I noticed the very same thing and came here looking for answers as well. Obviously, there is a problem and I’ve yet to find it.
The issue seems to come from the method_missing and method_missing_without_paginate around line 138 in the finder.rb file. I know that doesn’t really help anyone, but I just wanted to say that you are certainly not alone in this.
OK, I’ve found a little more. The problem definitely came into play with this update. http://dev.rubyonrails.org/changeset/9200
I’ve successfully managed to make things play nicely by subclassing HMTA from AssociationProxy instead of the changed to AssociationCollection. I did this by changing line 3 of activerecord/lib/active_record/associations/has_many_through_association.rb back to class HasManyThroughAssociation < AssociationProxy
I have done very little testing on this so use at your own peril, but a cursory look appears to suggest that I will only lose the include? function added in the above referenced patch, but the original functionality is at least temporarily fixed until further notice.
YMMV.
OK, one last post.
More investigating has found that the issue lies in how will_paginate mixes in the paginate method_missing magic.
In line 44 of finder.rb, will_paginate collects the classes of all AssociationCollection classes, then pushes associations::HasManyThrough into the array and adds the paginate missing method to all subclasses. However, since HasManyThrough is now descendent from AssociationCollection, this is unnecessary and seems to cause a redundancy by adding a missing method the 2nd time.
In order to make will_paginate work properly with projects running Rails versions before or after 9200, adding a call to uniq before each on line 44 seems to fix the problem.
- ).push(associations::HasManyThroughAssociation).each do |klass| + ).push(associations::HasManyThroughAssociation).uniq.each do |klass|
As before, I’ve just worked on this and testing is minimal, but it seems to be a 100% fix.
Just a note to all reading these last comments: issues with edge Rails have been fixed. If you find a bug, report it on Lighthouse.
I also got infinite loop error with one of the has_many associate using through.
Source is now @ http://github.com/mislav/will_paginate/wikis/installation
This plugin is awesome, we use it on every project. Thanks!
Can someone tell me what i’m missing that is making only the first page be returned no matter what :page I specify. I gotta be missing something simple here
Never mind stupid SQL Server doesn’t batch the results right unless there ordered … see ya soon Postgres
Chime in.