Module: LotusAdmin::FileStreamer
- Extended by:
- ActiveSupport::Concern
- Included in:
- AuthenticatedController
- Defined in:
- app/controllers/concerns/lotus_admin/file_streamer.rb
Instance Method Summary collapse
-
#index(&block) ⇒ Object
Usage.
Instance Method Details
#index(&block) ⇒ Object
Usage
def index
super do |format|
format.pdf { ... }
end
end
Will automatically stream CSV from configured exporter
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/concerns/lotus_admin/file_streamer.rb', line 41 def index(&block) super do |format| if self.class._exporter_class.present? format.csv do if self.class._exporter_filename.present? filename = instance_exec(&self.class._exporter_filename) end filename = "#{ resource_class.model_name.human(count: 2) }-exports-#{ SecureRandom.uuid }" if filename.blank? stream_file filename.parameterize, 'csv' do |stream| self.class._exporter_class.stream(ransack_object.result, stream) # full query, not just paginated end end end block.call(format) if block.present? end end |