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 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 2/6/07, archerid <aboostani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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, > ArashYou can stream it inline: class MyController < ApplicationController def get_file my_file = <<-FILE <your file contents here> FILE send_data my_file, :filename => ''myfile.xml'' end end Hope this helps. -- Zack Chandler http://depixelate.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 -~----------~----~----~----~------~----~------~--~---
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 archerid wrote:> 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 > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
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. On Feb 6, 11:18 am, "Zack Chandler" <zackchand...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 2/6/07,archerid<aboost...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > 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 > > You can stream it inline: > > class MyController < ApplicationController > > def get_file > my_file = <<-FILE > <your file contents here> > FILE > send_data my_file, :filename => ''myfile.xml'' > end > > end > > Hope this helps. > > -- > Zack Chandlerhttp://depixelate.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 -~----------~----~----~----~------~----~------~--~---