Skip to content

Instantly share code, notes, and snippets.

@awd
Created September 28, 2010 18:18
Show Gist options
  • Save awd/601480 to your computer and use it in GitHub Desktop.
Save awd/601480 to your computer and use it in GitHub Desktop.
# this responder allows the system to render a streaming proc
# rendering a proc was removed in Rails 3.0
ActionController::Renderers.add :csv do |proc, options|
raise ArgumentError "CSV responder requires :filename" unless options.key? :filename
filename = options[:filename]
headers.merge!(
'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
'Content-Disposition' => "attachment; filename=\"#{filename}\"",
'Content-Transfer-Encoding' => 'binary'
)
self.content_type ||= Mime::CSV
self.response_body = proc
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment