Module: ActiveRecordToCSV

Defined in:
lib/active_record_to_csv.rb

Instance Method Summary collapse

Instance Method Details

#to_csvObject

Return full CSV content with headers as string. Defined as class method which will have chained scopes applied.



6
7
8
9
10
11
12
13
14
15
# File 'lib/active_record_to_csv.rb', line 6

def to_csv
  csv_columns = column_names - %w{id created_at updated_at}
  header_row = csv_columns.to_csv
  records_rows = all.map do |record|
    csv_columns.map do |column|
      record[column]
    end.to_csv
  end.join
  header_row + records_rows
end