Skip to content

Instantly share code, notes, and snippets.

@foxumon
Created April 29, 2016 20:19
Show Gist options
  • Save foxumon/fdb30349545944eee58c7858e6bab23c to your computer and use it in GitHub Desktop.
Save foxumon/fdb30349545944eee58c7858e6bab23c to your computer and use it in GitHub Desktop.

Revisions

  1. foxumon created this gist Apr 29, 2016.
    12 changes: 12 additions & 0 deletions csv_export.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    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 }
    end
    end