Forum: Ruby on Rails Downloadable XML file

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
980f5824b1cd96f1882b7caf5bbaebdf?d=identicon&s=25 archerid (Guest)
on 2007-02-06 20:07
(Received via mailing list)
Hi All,

I'm trying to create an XML file that the user can download, but I'm
not sure how to do it. I'm able to create an action in my controller
that renders to a .rxml template, which allows the user to view the
XML in their browser window, but I don't want them to have to see the
XML, then save it to their computer. I'd like to have them click a
link and have a standard Save/Open dialog box (in IE) appear. Do I
need to save the XML file to my server filesystem first, or can I just
stream the file straight to the user?

Thanks in advance for your help,
C4dc94c893471878a105761a9207f29b?d=identicon&s=25 Zack Chandler (Guest)
on 2007-02-06 20:20
(Received via mailing list)
On 2/6/07, archerid <> wrote:
> stream the file straight to the user?
> Thanks in advance for your help,
> Arash

You can stream it inline:

class MyController <  ApplicationController

  def get_file
    my_file = <<-FILE
      <your file contents here>
    send_data my_file, :filename => 'myfile.xml'


Hope this helps.

Zack Chandler
8310c5a7c769345114597bcdef111488?d=identicon&s=25 Ben Munat (Guest)
on 2007-02-06 20:23
(Received via mailing list)
I think you need to set the header "Content-Disposition" to
"Attachment"... that makes the browser treat the file as something to
download. Can't remember off the top of my head how to set a response
header in rails, but google should help with that.

980f5824b1cd96f1882b7caf5bbaebdf?d=identicon&s=25 archerid (Guest)
on 2007-02-10 06:22
(Received via mailing list)
Thanks Zack & Ben.

I managed to get it working with a take-off on Zack suggestion. I used
send_data to write out the file like this:

send_data render :template=>"/route/gpx.rxml", :filename => "tb.xml"

It works like a charm.
This topic is locked and can not be replied to.