# Downloadable XML file

**URL:** <https://www.ruby-forum.com/t/downloadable-xml-file/84660>\
**Category:** Rails\
**Created:** [February 6, 2007, 8:07pm UTC](https://www.ruby-forum.com/t/downloadable-xml-file/84660 "2007-02-06T20:07:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![archerid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/97f17d/32.png) [@archerid](https://www.ruby-forum.com/u/archerid)\
**Post date:** [February 6, 2007, 8:07pm UTC](https://www.ruby-forum.com/t/downloadable-xml-file/84660/1 "2007-02-06T20:07:56Z")

</div>

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,  
Arash

---

<div class="post-metadata">

**Author:** ![archerid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/97f17d/32.png) [@archerid](https://www.ruby-forum.com/u/archerid)\
**Post date:** [February 6, 2007, 8:20pm UTC](https://www.ruby-forum.com/t/downloadable-xml-file/84660/2 "2007-02-06T20:20:01Z")

</div>

On 2/6/07, archerid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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  
  
FILE  
send\_data my\_file, :filename =\> ‘myfile.xml’  
end

end

Hope this helps.

–  
Zack C.  
[http://depixelate.com](http://depixelate.com)

---

<div class="post-metadata">

**Author:** ![archerid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/97f17d/32.png) [@archerid](https://www.ruby-forum.com/u/archerid)\
**Post date:** [February 6, 2007, 8:23pm UTC](https://www.ruby-forum.com/t/downloadable-xml-file/84660/3 "2007-02-06T20:23:01Z")

</div>

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.

b

---

<div class="post-metadata">

**Author:** ![archerid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/97f17d/32.png) [@archerid](https://www.ruby-forum.com/u/archerid)\
**Post date:** [February 10, 2007, 6:22am UTC](https://www.ruby-forum.com/t/downloadable-xml-file/84660/4 "2007-02-10T06:22:39Z")

</div>

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.
