Anil Bhat
11/14/2007 6:02:00 AM
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' %>