Skip to content

Instantly share code, notes, and snippets.

@queso
Created March 27, 2010 04:42
Show Gist options
  • Save queso/345729 to your computer and use it in GitHub Desktop.
Save queso/345729 to your computer and use it in GitHub Desktop.
### USAGE ###
# MODEL=User FILE="db/seed/development/user.csv" rake export_model
task :export_model => :environment do
MODEL = ENV["MODEL"].constantize
FILE = ENV["FILE"]
objects = MODEL.find(:all)
FasterCSV.open(File.join(Rails.root, FILE), "w") do |csv|
csv << MODEL.column_names
objects.each do |object|
csv << MODEL.column_names.map {|c| object.send(c)}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment