Skip to content

Instantly share code, notes, and snippets.

@geronimod
Created October 8, 2011 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geronimod/1271758 to your computer and use it in GitHub Desktop.
Save geronimod/1271758 to your computer and use it in GitHub Desktop.
csv_data = FasterCSV.generate do |csv|
# por ahora todas pero habra que dejar afuera la imagen y los templates html
# headers
csv << Product.columns.map(&:name)
Product.all.each do |record|
csv << Product.columns.map { |c| record.send(c.name) }
end
end
filename = "data-#{Time.now.to_date.to_s}.csv"
send_data(csv_string, :type => 'text/csv; charset=utf-8; header=present', :filename => filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment