How to download csv file

Hi,
i want a such code which helps me download a csv file to each client
machine when he click on download link, for this i am tried lots thing
but it working for IE, but not for mac, Mozilla, safari.
i want a optimum solution which works for all situation when i click on
link, it give me pop up saying where to download file. i need help that
what changes i do in controller on rhtml.
please reply.

On Wed, May 21, 2008 at 2:39 AM, Sunny B.
[email protected] wrote:

Hi,
i want a such code which helps me download a csv file to each client
machine when he click on download link, for this i am tried lots thing
but it working for IE, but not for mac, Mozilla, safari.
i want a optimum solution which works for all situation when i click on
link, it give me pop up saying where to download file. i need help that
what changes i do in controller on rhtml.
please reply.

In your controller action method, instead of using render, use either
send_data or send_file, e.g.

send_data("name,age\nfred,23\njoe,16\n", :filename => "data.csv",

:type => “text/csv”, :disposition => “attachment”)

The filename option will be used as a suggestion to the user for the
name of the downloaded file, type is the mimetype, and disposition of
attachment tells the browser to download rather than display the
downloaded file.

The default value for the disposition option is “attachment” so you
don’t really need to specify it, if you set it to “inline” then the
browser will display the file rather than downloading it.

The send_file method works similarly except that the first argument is
a string containing a path to a file on the server to be downloaded,
and there are two more options to control buffer sizes and whether or
not the file is sent as a stream or in chunks.

Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs