Forum: Ruby on Rails Downloading a CSV file

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C4bfcc81ac9281cb905f38e97e4d4e0b?d=identicon&s=25 Shandy Nantz (snantz)
on 2008-11-03 16:58
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
F0f0a1f3ffb784d0b3b00941f846e7e0?d=identicon&s=25 Rui Neto (ruivaldo)
on 2008-11-03 17:36
(Received via mailing list)
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 Nantz
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2008-11-03 18:04
Wouldn't send_data work for this?

http://api.rubyonrails.org/classes/ActionControlle...

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 Nantz
C4bfcc81ac9281cb905f38e97e4d4e0b?d=identicon&s=25 Shandy Nantz (snantz)
on 2008-11-03 18:08
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 Nantz

What I ended up doing is adding this line:

headers['Cache-Control'] = 'private'

thanks for the responce,

-S
This topic is locked and can not be replied to.