Created
February 26, 2017 21:10
-
-
Save bibarsov/a7cf48068ed36f5742a5b17d8e2a7de2 to your computer and use it in GitHub Desktop.
Export to CSV from Rails Console
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
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