Sha256: 40f7476a0d0e3b2b1706bc29bad003e3e15fba274d40b39426019fc1bc1c72df
Contents?: true
Size: 940 Bytes
Versions: 20
Compression:
Stored size: 940 Bytes
Contents
require 'csv' module ActiveAdmin class ResourceController < BaseController # This module overrides CSV responses to allow large data downloads. # Could be expanded to JSON and XML in the future. # module Streaming def index super do |format| format.csv { stream_csv } yield(format) if block_given? end end protected def stream_resource(&block) headers['X-Accel-Buffering'] = 'no' headers['Cache-Control'] = 'no-cache' self.response_body = Enumerator.new &block end def csv_filename "#{resource_collection_name.to_s.gsub('_', '-')}-#{Time.zone.now.to_date.to_s(:default)}.csv" end def stream_csv headers['Content-Disposition'] = %{attachment; filename="#{csv_filename}"} stream_resource &active_admin_config.csv_builder.method(:build).to_proc.curry[self] end end end end
Version data entries
20 entries across 20 versions & 3 rubygems