tags:

views:

718

answers:

4

i am exporting data to csv,

while exporting i want to split by every 50 records, instead of exporting all together.

(i.e, if i click "Export to CSV" it should export first 50 records, later again on clicking "Export to csv" it should export next 50 records and so on)

please, provide me some code to solve this problem.

thanks

+1  A: 
records = ModelClass.find(:limit => 50, ...)
# convert records to CSV

# later:
records = ModelClass.find(:limit => 50, :offset => 50, ...)
+1  A: 

Looks like you want pagination (you do a 50 record per page)

There's a plugin for that: will_paginate

then you do: Model.paginate :page => params[:page], :per_page => 50

and just add 1 to your page everytime

amikazmi
+2  A: 

If pagination is not required you could try AR#find_in_batches.

Record.find_in_batches(:batch_size => 50) do |records|
  export_to_csv(records) # max 50 records
end
splattael
A: 

this is not working,using pagination.can you help me

honey