Skip to content

Instantly share code, notes, and snippets.

View NateJBeck's full-sized avatar

Nathan NateJBeck

View GitHub Profile
@foxumon
foxumon / csv_export.rb
Created April 29, 2016 20:19
Export table to CSV with all attributes in rails console
require 'csv'
file = "#{Rails.root}/public/data.csv"
table = User.all;0 # ";0" stops output. Change "User" to any model.
CSV.open( file, 'w' ) do |writer|
writer << table.first.attributes.map { |a,v| a }
table.each do |s|
writer << s.attributes.map { |a,v| v }