# Read file into array

**URL:** <https://www.ruby-forum.com/t/read-file-into-array/120142>\
**Category:** Ruby\
**Created:** [November 14, 2007, 2:59am UTC](https://www.ruby-forum.com/t/read-file-into-array/120142 "2007-11-14T02:59:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brianspaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/82dd89/32.png) [@brianspaid](https://www.ruby-forum.com/u/brianspaid)\
**Post date:** [November 14, 2007, 2:59am UTC](https://www.ruby-forum.com/t/read-file-into-array/120142/1 "2007-11-14T02:59:21Z")

</div>

Hello,

What are examples of reading a csv file (Comma) into an Array

---

<div class="post-metadata">

**Author:** ![brianspaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/82dd89/32.png) [@brianspaid](https://www.ruby-forum.com/u/brianspaid)\
**Post date:** [November 14, 2007, 5:06am UTC](https://www.ruby-forum.com/t/read-file-into-array/120142/2 "2007-11-14T05:06:18Z")

</div>

On Nov 13, 6:58 pm, Brian S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> What are examples of reading a csv file (Comma) into an Array

On the Internet.

---

<div class="post-metadata">

**Author:** ![brianspaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/82dd89/32.png) [@brianspaid](https://www.ruby-forum.com/u/brianspaid)\
**Post date:** [November 14, 2007, 7:05am UTC](https://www.ruby-forum.com/t/read-file-into-array/120142/3 "2007-11-14T07:05:30Z")

</div>

On Nov 14, 9:05 am, Phrogz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Nov 13, 6:58 pm, Brian S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > What are examples of reading a csv file (Comma) into an Array
> 
> On the Internet.

May be the following code will help you:  
def member\_data  
member = Member.find(:all)  
stream\_csv do |csv|  
csv \<\< [“First Name”,“Last Name”,“Email”]  
member.each do |u|  
csv \<\< [u.first\_name,u.last\_name,u.email]  
end  
end  
end

Explanation: Member is the model name. First name, last name and email  
are the fields shown while downloading CSV.  
Following code to be written in rhtml file:  
\<%= link\_to ‘download’, :controller =\> ‘reports’, :action =\>  
‘member\_data’ %\>
