Sha256: de28af3380e82910f9974c2e796f517ec439d9dd3414ca5e83adcc1d4f911320
Contents?: true
Size: 523 Bytes
Versions: 130
Compression:
Stored size: 523 Bytes
Contents
module ControllerMixins module CsvInstanceMethods require 'csv' def to_csv(objects, skip_attributes=[], delimiter= ",") return "" if objects.blank? objects_class = objects.first.class filtered_columns = objects_class.column_names - skip_attributes CSV.generate do |csv| csv << filtered_columns objects.each do |object| csv << filtered_columns.collect { |a| object.attributes[a].blank? ? '' : "'#{object.attributes[a]}'" } end end end end end
Version data entries
130 entries across 130 versions & 1 rubygems