Skip to content

Instantly share code, notes, and snippets.

@jamster
Created January 7, 2011 16:07
Show Gist options
  • Select an option

  • Save jamster/769655 to your computer and use it in GitHub Desktop.

Select an option

Save jamster/769655 to your computer and use it in GitHub Desktop.
simple way to create a csv (or tsv) of AR records
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