[Rails] Re: using a paginate method to display the second group of 25 records on page 2

2011-03-27 Thread Matt Jones
On Mar 25, 4:33 pm, John Merlino wrote: > Here's the method: > > def paginate(resources) >    @all_resources = resources >   @limit = (params[:limit] && params[:limit].to_i) || 25 >   @page = (params[:page] && params[:page].to_i) || 1 >   @page_index = @page - 1 >   @offset = @page_index * @limit

[Rails] Re: using a paginate method to display the second group of 25 records on page 2

2011-03-25 Thread John Merlino
> Suppose 90 records... > ((90-1)/30).to_i + 1 = 3, 3 full pages > > It's just some math hijinks to make sure any partial page isn't missed > in the page count. Thanks that was very helpful. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to th

[Rails] Re: using a paginate method to display the second group of 25 records on page 2

2011-03-25 Thread Ar Chron
John Merlino wrote in post #989291: > > ((@all_resources.size - 1) / @limit).to_i + 1 > > What does the size method do and why add one at the end? > Suppose 100 records, with a page size of 30 num_pages = ((100-1)/30) num_pages = 99/30 num_pages = 3.3 num_pages = 3 (to_i) num_pages = 4 3 full pa