# Export to CSV

**URL:** <https://www.ruby-forum.com/t/export-to-csv/174785>\
**Category:** Rails\
**Created:** [September 2, 2009, 7:20am UTC](https://www.ruby-forum.com/t/export-to-csv/174785 "2009-09-02T07:20:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lamrin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@lamrin](https://www.ruby-forum.com/u/lamrin)\
**Post date:** [September 2, 2009, 7:20am UTC](https://www.ruby-forum.com/t/export-to-csv/174785/1 "2009-09-02T07:20:56Z")

</div>

in 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

---

<div class="post-metadata">

**Author:** ![lamrin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@lamrin](https://www.ruby-forum.com/u/lamrin)\
**Post date:** [September 2, 2009, 1:59pm UTC](https://www.ruby-forum.com/t/export-to-csv/174785/2 "2009-09-02T13:59:58Z")

</div>

Really? Two posts?
