Skip to content

Instantly share code, notes, and snippets.

@bibarsov
Created February 26, 2017 21:10
Show Gist options
  • Save bibarsov/a7cf48068ed36f5742a5b17d8e2a7de2 to your computer and use it in GitHub Desktop.
Save bibarsov/a7cf48068ed36f5742a5b17d8e2a7de2 to your computer and use it in GitHub Desktop.
Export to CSV from Rails Console
require 'csv'
file = "#{Rails.root}/public/data.csv"
schools = School.where(state_code: 'CO').order('name ASC')
CSV.open( file, 'w' ) do |writer|
schools.each do |s|
writer << [s.name, s.zipcode, s.id]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment