On Oct 28, 2011, at 3:15 AM, Hussam Ali wrote:
>> And then your index.html.erb would be exactly the same as it currently
>> is, with the pagination and whatnot, and your index (controller) method
>> would also be the same, with no worries about making the pagination
>> smarter. Wherever you wanted your random sample to appear, you would
>> simply use the sample method. And your index would be a normal index
>> without any notion of randomness, so any possible foo could be shown or
>> found.
>
> Thanks Walter, i appreciate your efforts, i understand your point here,
> but what you are saying is to have two separate things, my point is to
> show random items with pagination, we can show random items as shown
> above but we cannot accommodate this thing with our overall pagination,
> e.g
>
> def index
> @foo = Foo.order('created_at Desc').paginate :page => params[:page],
> :per_page => @per_page
> end
>
> As u are saying this would remain the same but my point is that we have
> to accommodate that random sample method in the first page rather than
> to have it separate from pagination. As in the above index method how
> can we pass sample in it just for first page?
I'm making a more fundamental point. If you randomize the sort when making your first page, it may not contain some elements that would ordinarily be found in the first page (when sorted deterministically). So you look at those things, and then you move on to page 2, which may contain elements you already saw on page 1 (remember, that was randomized) along with the rest of the next page of sorted elements. And so on. So at each page after 1, you have a fair chance of seeing a repeat, and you also have a statistically high chance of never seeing some of the elements that would have appeared on the first page, and this chance goes up the larger your total population of elements becomes. When you move to page 2, your sorting mechanism assumes you've seen everything that would sort to page 1, and never shows it to you again.
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