[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Read file into array

Brian Scott

11/14/2007 1:59:00 AM

Hello,

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

2 Answers

Phrogz

11/14/2007 4:05:00 AM

0

On Nov 13, 6:58 pm, Brian Scott <cui...@network32.net> wrote:
> What are examples of reading a csv file (Comma) into an Array

On the Internet.

Anil Bhat

11/14/2007 6:02:00 AM

0

On Nov 14, 9:05 am, Phrogz <phr...@mac.com> wrote:
> On Nov 13, 6:58 pm, Brian Scott <cui...@network32.net> 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' %>