Skip to content

Instantly share code, notes, and snippets.

@geronimod
Created October 8, 2011 00:47
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/1271686 to your computer and use it in GitHub Desktop.
Save geronimod/1271686 to your computer and use it in GitHub Desktop.
def to_csv
header = Product.columns.map(&:name).join(',')
rows = Product.all.map do |record|
returning [] do |row|
Product.columns.each { |c| row << record.send(c) }
end.join(',')
end
[header, rows.join("\n")].join("\n")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment