Newbies: Read this before asking about pagination

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

http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/63d0aee496998a99/a415d6df0fbb6957#a415d6df0fbb6957

http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/fcb0000ac2959193/80bc69f22efdf44f#80bc69f22efdf44f

good writeup, i think this would be worthwhile for the FAQ (assuming the author wants to start building out the page:

http://www.faisal.com/docs/ror-list-faq.html

another great alternative is the paginator gem.

http://paginator.rubyforge.org/

I am looking to setup a "test deployment" server for rails and I was wondering everyone input on which is a good solution to work on.

According to litespeed using only their server with ruby-lsapi is the ONLY way to go :stuck_out_tongue:

I would just like some realworld experience.

Thanks!

I am looking to setup a "test deployment" server for rails and I was wondering everyone input on which is a good solution to work on.

According to litespeed using only their server with ruby-lsapi is the ONLY way to go :stuck_out_tongue:

I would just like some realworld experience.

Thanks!

we use apache + mongrel at work. easy setup and we have never had a problem. no experience with litespeed.

good luck in your decision.

Do you have any pointers on setting this up? I have a FreeBSD server
which I am quite fluent with. Not so much with apache or mongrel.

Regards, Ron

Ron,

I run multiple environments (apache + mongrels, apache + litespeed, litespeed only) and I can't tell you nothing beats litespeed in how easy it is to setup and how fast and stable it is. Recently I benchmarked one of my apps both with mongrel, mongrel + evented and litespeed and LS was not only faster but required less RAM. My mongrel processes started at 33MB and grew into 60-70MB while the Ruby processes under LS stayed at 33MB. And we are talking under sets of 100K requests on 5/10/50 concurrent requests. For me there is no discussion now, LS all the way.

Hope it helps,

Adrian Madrid

How well did the Apache + Mongrel do? I have a similar situation as the OP but I have less options at this time to experiment with. The only 2 I really have right now is Apache + Mongrel or Apache + FCGI.

TIA, Richard

Defiantly do not do FCGI.

-Ron

I can second litespeed. It's pretty nice, just be sure to give the docs a good read to understand their GUI and stuff. It's not hard, but the docs will help give you a good understanding of how it works.

One nice thing about litespeed is that it can spawn/kill off the lsapi processes based on load. Which is nice for my little server with lots of rails apps, but very little traffic (ie, me and my family usually).

I've used mongrel too and it's very nice as well, but the ram is used all the time regardless of whether or not you're getting any traffic.

I was playing around with litespeed last night for the first time and was impressed. It's main advantage IMO over the typical http server -> mongrel cluster -> rails setup is that it has fewer moving parts. A mongrel setup typically has something like monit running also.

So far it's my favorite, and I've tried pretty much everything, including jruby on rails and mongrels running under smf in solaris behind a hardware load balancer (which is my second favorite).

Chris