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.
Shandy N. (Guest)
on 2008-11-03 17: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
Rui N. (Guest)
on 2008-11-03 18: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 N.
Robert W. (Guest)
on 2008-11-03 19: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 N.
Shandy N. (Guest)
on 2008-11-03 19: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 N.

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.