On Wed, May 21, 2008 at 2:39 AM, Sunny Bogawat
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
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/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---