Skip to content

Instantly share code, notes, and snippets.

@mattantonelli
Created December 2, 2022 14:05
Show Gist options
  • Save mattantonelli/1115e7f91dcde77b7f52563cc7a21ace to your computer and use it in GitHub Desktop.
Save mattantonelli/1115e7f91dcde77b7f52563cc7a21ace to your computer and use it in GitHub Desktop.
Simple dump of specified columns for a Rails model
headers = %w(column1 column2 column3)
CSV.open('tmp/output.csv', 'wb') { |csv| csv << headers; MyModel.each { |app| csv << app.attributes.values_at(*headers) } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment