# Downloading a CSV file

**URL:** <https://www.ruby-forum.com/t/downloading-a-csv-file/152408>\
**Category:** Rails\
**Created:** [November 3, 2008, 4:58pm UTC](https://www.ruby-forum.com/t/downloading-a-csv-file/152408 "2008-11-03T16:58:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [November 3, 2008, 4:58pm UTC](https://www.ruby-forum.com/t/downloading-a-csv-file/152408/1 "2008-11-03T16:58:08Z")

</div>

I have this app where users can look-up certain information and then  
save it into a CSV file. My problem is that when a user using IE7 tries  
to save this file I get an error saying something to the effect that  
“unable to downlaod because the website could not be contacted,” blah  
blah blah. But, in Chrome and Opera the downloading works fine.

stream\_csv do |csv|  
csv \<\< [“Sort One”, “Sort Two”, “Sort Three”]  
@unusedtickets.each do |unusedticket|  
csv \<\< [ unusedticket.sort1, unusedticket.sort2,  
unusedticket.sort3,]  
end  
end

This is the code that makes the CSV file, I don’t know it will help but  
here it is.

Has anyway come across this kind of thing? Thanks,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [November 3, 2008, 5:36pm UTC](https://www.ruby-forum.com/t/downloading-a-csv-file/152408/2 "2008-11-03T17:36:52Z")

</div>

Try to set the headers in the start of your action, something like this:

headers[‘Content-Type’] = “application/vnd.ms-excel”  
headers[‘Content-Disposition’] = ‘attachment;  
filename=“excel-export.xls”’  
headers[‘Cache-Control’] = ‘’

Cheers.

[rui]  
[Seiri, Seiton, SeisÅ, Seiketsu e Shitsuke]

On Mon, Nov 3, 2008 at 12:58 PM, Shandy N.

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [November 3, 2008, 6:04pm UTC](https://www.ruby-forum.com/t/downloading-a-csv-file/152408/3 "2008-11-03T18:04:22Z")

</div>

Wouldn’t send\_data work for this?

> **[ActionController::Streaming](https://api.rubyonrails.org/classes/ActionController/Streaming.html#M000254)**
>
> Allows views to be streamed back to the client as they are rendered. By default, Rails renders views by first rendering the template and then the layout.

Rui Neto wrote:

> Try to set the headers in the start of your action, something like this:
> 
> headers[‘Content-Type’] = “application/vnd.ms-excel”  
> headers[‘Content-Disposition’] = ‘attachment;  
> filename=“excel-export.xls”’  
> headers[‘Cache-Control’] = ‘’
> 
> Cheers.
> 
> [rui]  
> [Seiri, Seiton, SeisÅ, Seiketsu e Shitsuke]
> 
> On Mon, Nov 3, 2008 at 12:58 PM, Shandy N.

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [November 3, 2008, 6:08pm UTC](https://www.ruby-forum.com/t/downloading-a-csv-file/152408/4 "2008-11-03T18:08:01Z")

</div>

Rui Neto wrote:

> Try to set the headers in the start of your action, something like this:
> 
> headers[‘Content-Type’] = “application/vnd.ms-excel”  
> headers[‘Content-Disposition’] = ‘attachment;  
> filename=“excel-export.xls”’  
> headers[‘Cache-Control’] = ‘’
> 
> Cheers.
> 
> [rui]  
> [Seiri, Seiton, SeisÅ, Seiketsu e Shitsuke]
> 
> On Mon, Nov 3, 2008 at 12:58 PM, Shandy N.

What I ended up doing is adding this line:

headers[‘Cache-Control’] = ‘private’

thanks for the responce,

-S
