Thursday, October 27, 2011

Re: [Rails] Re: Different Order by clause on will_paginate pages?

On Oct 27, 2011, at 2:46 AM, Hussam Ali wrote:

> Frederick Cheung wrote in post #1028581:
>> On Oct 26, 10:25am, Hussam Ali <li...@ruby-forum.com> wrote:
>>> pagination. Anybody have any idea?
>>>
>>
>> That sounds like two mutually contradictory aims. You could perhaps
>> have a single 'random' page and then a series of paginated by
>> created_at pages.
>> If you absolutely had to present the illusion of the first page being
>> a random selection, you could also fiddle with the page parameter - if
>> it's 1 show a random selection, if it's greater than one subtract 1
>> and pass that to will_paginate
>>
>> Fred
>
>
> Ok i got your point, i have done this and it works,
>
> if params[:page].to_i > 1
> order by created_at
> else
> order by random
> end
>
> Is there any other possible approach of handling it or how can i make
> the above code more efficient??????
>

I think you're missing one thing here. This precise construction means that there is a significant chance that some items will never be seen at all. If the first "page" is random, it's not "random within the parameters of what would otherwise land on page 1", it's "random across the entire database". And then you move to page 2, where it's created_at über alles.

What I would do is have a separate route for "random tease of what's in the database", and then have a real "everything, in order" route as is normal for an index + pagination.

Walter
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment