Created
April 18, 2015 06:00
-
-
Save morshedalam/d24b78ac5718691190ad to your computer and use it in GitHub Desktop.
Export to CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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