Last active
August 29, 2019 11:16
-
-
Save mec/90f2d9944fb5a34ddb8d944187a2366d to your computer and use it in GitHub Desktop.
Export objects to csv from the Rails console
This file contains 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 = "path/to/file" | |
CSV.open("tmp/schools_mp.csv", "wb") do |csv| | |
csv << School.attribute_names | |
School.includes(:local_authority, :local_authority_district).select(&:condition?).each do |school| | |
csv << school.attributes.values | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment