21 行
925 B
Ruby
21 行
925 B
Ruby
class CountsExportsController < ApplicationController
|
|
wrap_parameters false
|
|
|
|
def index
|
|
locale = resolve_locale!
|
|
exporter = CountsExporter.new(request.request_parameters.merge(request.query_parameters),
|
|
language_code: locale.language_code)
|
|
response.headers['Content-Type'] = exporter.format == 'json' ?
|
|
'application/json; charset=utf-8' : 'text/csv; charset=utf-8'
|
|
response.headers['Content-Disposition'] =
|
|
"attachment; filename=\"counts-#{ exporter.resource }.#{ exporter.format }\""
|
|
response.headers['Cache-Control'] = 'private, no-store'
|
|
response.headers['X-Accel-Buffering'] = 'no'
|
|
# Rack::ETag otherwise materialises the response to calculate a digest.
|
|
response.headers['Last-Modified'] = Time.current.httpdate
|
|
self.response_body = exporter.body
|
|
rescue ArgumentError, TypeError, JSON::ParserError
|
|
head :bad_request
|
|
end
|
|
end
|