Module: Locomotive::Extensions::ContentEntry::Csv::ClassMethods
- Defined in:
- app/models/locomotive/extensions/content_entry/csv.rb
Instance Method Summary collapse
-
#to_csv(options = {}) ⇒ String
Generate a csv from a collection of content entries.
Instance Method Details
#to_csv(options = {}) ⇒ String
Generate a csv from a collection of content entries
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/models/locomotive/extensions/content_entry/csv.rb', line 58 def to_csv( = {}) content_type = .delete(:content_type) || all.first.try(:content_type) = .select do |k, v| CSV::DEFAULT_OPTIONS.keys.include?(k.to_sym) end fields = content_type.ordered_entries_custom_fields labels = fields.map(&:label) << I18n.t('mongoid.attributes.locomotive/content_entry.created_at') CSV.generate() do |csv| # header csv << labels # body all.each_by(100) do |entry| csv << entry.to_values() end end end |