Downloadable XML file

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

On 2/6/07, archerid [email protected] 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

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

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