Skip to content

Instantly share code, notes, and snippets.

@alebian
Created April 17, 2016 21:26
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 alebian/128625193188a4017f1fa1b4ed68093f to your computer and use it in GitHub Desktop.
Save alebian/128625193188a4017f1fa1b4ed68093f to your computer and use it in GitHub Desktop.
Model records to CSV
require 'csv'
CSV.open("path/to/file.csv", "wb") do |csv|
csv << Model.attribute_names
Model.find_each do |model|
csv << model.attributes.values
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment