-1

Want to show the records satisfying some condition after retrieving it from the database in Ruby on rails.

Problem is that :

currently I am showing the records using will_paginate gem without checking the condition after retrieving it from database.

and if I check the condition ; some records fail to meet the condition will be eliminated

EDIT

@result=MyRecord.paginate(:per_page => @perpage, :page => params[:page]).all
 #process records for conditions, if i eliminate records from @result that much records will be less for pagination
 @result #modified sent to view

So how to show the pagination for this.

Is their any alternative way to do the pagination after retrieving the records???

Mohammad Sadiq Shaikh
  • 3,160
  • 9
  • 35
  • 54

1 Answers1

1

If I understood correctly, if you are getting less records which in turn not giving pagination then you can explicitly define your pagination for the number of records you want with the attribute :per_page. So if you are getting only five records from database then define :per_page => 5 in your query to get the pagination.

This way you can go -

@result=MyRecord.paginate(:per_page => 5, :page => params[:page]).all

For varying results, WillPaginate::Collection will also help -

Check this post of SO - rails pagination - different per_page value page 1 from subsequent pages

Community
  • 1
  • 1
sjain
  • 23,126
  • 28
  • 107
  • 185
  • I am retriving per page 10 records .but @result is to be procesed to meet my condition . if some records fails to meet it .Total records will be reduced for that page.... – Mohammad Sadiq Shaikh Jan 08 '13 at 13:13
  • I edited my post to give you the better solution that you want. Check my updated answer above. – sjain Jan 08 '13 at 13:27