I’ve just read three* different messages on the list, all posted
within a day of each other, and all having problems with the same
thing - rails built in pagination.
The common misconception seems to be that rails built in pagination
works as follows:
grab a list of all the females
@users = User.find(:all, :conditions => [‘gender = ?’, ‘F’])
paginate the list:
@user_pages, @users = paginate(:users, :per_page => 10)
The above will paginate a list of users, however, it will NOT have the
conditions applied to it that you specified in the first find
statement (grabbing a list of females). The two statements are not
related to each other. The first finds all the females and stores the
results in the @users instance variable. The second finds and
paginates ALL of the users and stores them in the @users ivar,
overwriting the original contents. This is most likely not what you
want.
If you wanted to paginate a list of all the females, the correct way
to do it is the following
paginate a list of females
@user_pages, @users = paginate(:users, :conditions => [‘gender = ?’,
‘F’], :per_page => 10)
now, having said that, please be aware that the rails built in
pagination has been deprecated! (see here for more details
http://dev.rubyonrails.org/changeset/6992) In other words, do not use
it for future projects!
Instead, you should be using something like the will_paginate plugin
(you can read about it here: http://errtheblog.com/post/4791)
Hopefully this will help reduce some confusion…
Mike
- the messages I’m referring to…
http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/92190b21dc5c08f5/f4849b96c2b5a943#f4849b96c2b5a943