Created
January 7, 2011 16:07
-
-
Save jamster/769655 to your computer and use it in GitHub Desktop.
simple way to create a csv (or tsv) of AR records
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def to_csv(array_of_ar_objects, delim=",") | |
| keys = array_of_ar_objects.first.attributes.keys | |
| puts keys.join(delim) | |
| array_of_ar_objects.map do |item| | |
| keys.map{|key| item.send(key)}.join(delim) | |
| end.join("\n") | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment