Skip to content

Instantly share code, notes, and snippets.

@noel
Created September 15, 2010 16:44
Show Gist options
  • Save noel/581024 to your computer and use it in GitHub Desktop.
Save noel/581024 to your computer and use it in GitHub Desktop.
@items = MyModel.all
@columns = MyModel.column_names
respond_to do |format|
format.csv do
my_csv = FasterCSV.generate do |csv|
# header row
csv << @columns
# data rows
line = []
@items.each do |item|
@columns.each do |column|
line << [item.send(column).to_s]
end
csv << line
line = []
end
end
send_data(my_csv, :type => 'text/csv', :filename => 'my_csv.csv')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment