Skip to content

Instantly share code, notes, and snippets.

@morshedalam
Created April 18, 2015 06:00
Show Gist options
  • Save morshedalam/d24b78ac5718691190ad to your computer and use it in GitHub Desktop.
Save morshedalam/d24b78ac5718691190ad to your computer and use it in GitHub Desktop.
Export to CSV
module Exportable
extend ActiveSupport::Concern
module ClassMethods
def to_csv(options = {})
columns = options[:columns] || column_names
CSV.generate do |csv|
csv << columns
all.each do |item|
csv << item.attributes.values_at(*columns)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment