0

for Export to CSV, i have overall 2500 records, and while exporting it takes long time to export all records, so, i have decided to export in the form of 1st 50 students,and, 2nd 50 students,so on. I have tried the below code. but it could able to fetch only 1st 50 students. please, guide me how to solve the problem

def exportcsv

  @student_count = Student.find(:all)

  @count1 = @student_count.count

  st_per_file = 50

  count = 0

  unless @count1==count

  students = Student.find(:all, :order => 'name', :limit =>
               st_per_file, :offset => (st_per_file*count))

  count = count + 1


 filename = 'students.csv'

  headers.merge!(

    'Content-Type' => 'text/csv',

    'Content-Disposition' => "attachment; filename=\"#{filename}\"",

    'Content-Transfer-Encoding' => 'binary'
  )
 --------------
 --------------
  end

end
Yuval F
  • 20,565
  • 5
  • 44
  • 69
Senthil Kumar Bhaskaran
  • 7,371
  • 9
  • 43
  • 56

3 Answers3

2

Didn't we just answer this yesterday? I don't really see what has changed between the two other than there is more code now.

Community
  • 1
  • 1
theIV
  • 25,434
  • 5
  • 54
  • 58
2

2500 records isn't very much, this smells in my opinion. Sounds like you should be sorting out why this is so bad.

nitecoder
  • 5,496
  • 1
  • 28
  • 35
0

You need to have a loop to do this. Ruby's 'unless' keyword is a negated if and only runs once. Try a 'while' or an 'until'.

Yuval F
  • 20,565
  • 5
  • 44
  • 69