Saving an XML File
Wednesday
Sep 02, 2009
5:00 am
For my backup solution, I am generating and XML file of all my posts and burning them to CD with my regular backups on my local machine. I wrote an action and a Haml view to take care of generating this, but when I hit that URL, Firefox would display the XML on screen instead of offering to save it.
It took me too long to solve this ever to waant to do so again. The solution is to add a header with a key of 'Content-Disposition' and a value of 'attachement; filename=backup.xml' I'm not sure that everyone will agree that it is the correct place for it, but I added this to my view as:
#!/xml
- headers['Content-Disposition'] = 'attachment; filename=backup.xml'
!!! xml
...
This lets me keep my backup action serving both an HTML form and the XML backup file with no extra logic needed.