Module: Locomotive::Concerns::ContentEntry::Csv::ClassMethods
- Defined in:
- app/models/locomotive/concerns/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 76 77 78 79 |
# File 'app/models/locomotive/concerns/content_entry/csv.rb', line 58 def to_csv( = {}) # puts "to_csv #{all.count.inspect} / #{all.first.inspect}" # puts "#{all.first.content_type_id.inspect}" # puts "#{all.first.content_type.inspect}" # binding.pry 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 |