Skip to content

Commit 471aa34

Browse files
committed
Don't stream CSV in development
This enables any exceptions to bubble up, instead of waiting until the request times out before sending back any data. This also lets you use in-browser debuggers, like better_errors.
1 parent 5536b15 commit 471aa34

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

lib/active_admin/application.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ def initialize
125125
:email,
126126
:to_s ]
127127

128+
# To make debugging easier, by default don't stream in development
129+
setting :disable_streaming_in, ['development']
130+
128131
# == Deprecated Settings
129132

130133
def allow_comments=(*)

lib/active_admin/csv_builder.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,31 @@ def column(name, options={}, &block)
3939
@columns << Column.new(name, @resource, column_transitive_options.merge(options), block)
4040
end
4141

42-
def build(controller, receiver)
42+
def build(controller, csv)
4343
@collection = controller.send(:find_collection, except: :pagination)
4444
options = ActiveAdmin.application.csv_options.merge self.options
4545
columns = exec_columns controller.view_context
4646

4747
if byte_order_mark = options.delete(:byte_order_mark)
48-
receiver << byte_order_mark
48+
csv << byte_order_mark
4949
end
5050

5151
if options.delete(:column_names) { true }
52-
receiver << CSV.generate_line(
52+
csv << CSV.generate_line(
5353
columns.map { |c| encode c.name, options },
5454
options.except(:encoding_options))
5555
end
5656

5757
(1..paginated_collection.total_pages).each do |page_no|
5858
paginated_collection(page_no).each do |resource|
5959
resource = controller.send :apply_decorator, resource
60-
receiver << CSV.generate_line(
60+
csv << CSV.generate_line(
6161
build_row(resource, columns, options),
6262
options.except(:encoding_options))
6363
end
6464
end
65+
66+
csv
6567
end
6668

6769
def exec_columns(view_context = nil)

lib/active_admin/resource_controller/streaming.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ def index
2020
def stream_resource(&block)
2121
headers['X-Accel-Buffering'] = 'no'
2222
headers['Cache-Control'] = 'no-cache'
23-
self.response_body = Enumerator.new &block
23+
24+
if ActiveAdmin.application.disable_streaming_in.include? Rails.env
25+
self.response_body = block['']
26+
else
27+
self.response_body = Enumerator.new &block
28+
end
2429
end
2530

2631
def csv_filename

0 commit comments

Comments
 (0)