Forum: Ruby on Rails Output non-HTML (CSV) from Rails

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
D105b980e30e1b77fc761b1cd1b2de32?d=identicon&s=25 unknown (Guest)
on 2006-01-11 17:04
(Received via mailing list)

I want to offer a CSV download of data in my Rails app (eg. An "Export
to Excel" link to grab the current view of tabulated data).

However, I can't seem to break-out of the Rails framework to output this
non-HTML data. Even if I eliminate my layout template from my view, the
most basic view (no HTML) will still wrap the output in
<html><body></body></html> tags.

Does anyone have a recommended way to do this within Rails?

Thank you!


Matt C. Wagner
Information Security Analyst

Network Intrusion Detection
Security Operations Center
Corporate Information Security
Wells Fargo Bank
F15fdc7cb2e911b3808837f2be244add?d=identicon&s=25 Adam Denenberg (Guest)
on 2006-01-11 17:14
(Received via mailing list)
you need to change the Content-Type that you send to the browser to be
of type CSV.   Something like Content-type: application/

Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-01-11 17:27
(Received via mailing list) wrote:
> Does anyone have a recommended way to do this within Rails?
In the controller:

   response.headers['Content-Disposition'] => 'attachment'
   response.headers['Content-Type'] => 'text/csv'
   render :text => @csv_contents, :layout => false
8acba6d057b3f0c2c16cca95ad36881b?d=identicon&s=25 Bakki Kudva (bakki)
on 2006-01-11 21:02
(Received via mailing list)
Hi Matt,

Have you tried send_data or send_file which are " Methods for sending
and streams to the browser instead of rendering."
I have used send_data to send and image to the browser. Check out my

-bakki kudva

On 1/11/06, <>
895a112c66d93cefcd06d2cf371219e6?d=identicon&s=25 Hasan Diwan (Guest)
on 2006-01-11 23:31
(Received via mailing list)
Mr Wagner:
On Jan 11, 2006, at 8:02 AM, <>
<> wrote:
> Does anyone have a recommended way to do this within Rails?

render_without_layout 'template' which defaults to the same name as
your action.
Hasan Diwan <>
This topic is locked and can not be replied to.