# Creating xml files on the hard disk

**URL:** <https://www.ruby-forum.com/t/creating-xml-files-on-the-hard-disk/90346>\
**Category:** Rails\
**Created:** [March 28, 2007, 1:43am UTC](https://www.ruby-forum.com/t/creating-xml-files-on-the-hard-disk/90346 "2007-03-28T01:43:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d6d6ee/32.png) [@luma](https://www.ruby-forum.com/u/luma)\
**Post date:** [March 28, 2007, 1:43am UTC](https://www.ruby-forum.com/t/creating-xml-files-on-the-hard-disk/90346/1 "2007-03-28T01:43:32Z")

</div>

I’ve written a rxml template. What must I write in my rails-controller  
to get xml files out of this - not displayed on the screen, but just  
saved on the hard disk? And where do I have to store the rxml file?

---

<div class="post-metadata">

**Author:** ![luma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d6d6ee/32.png) [@luma](https://www.ruby-forum.com/u/luma)\
**Post date:** [March 28, 2007, 6:16am UTC](https://www.ruby-forum.com/t/creating-xml-files-on-the-hard-disk/90346/2 "2007-03-28T06:16:57Z")

</div>

Well, if you already have a controller and the rxml template, then all  
you need do to get the xml written to the file system is to turn on page  
caching for that action. Check out the docs:

[http://api.rubyonrails.org/classes/ActionController/Caching/Pages.html#M000110](http://api.rubyonrails.org/classes/ActionController/Caching/Pages.html#M000110)

There’s also good coverage of caching in the agile rails book. Plus  
google will probably give you a lot of help too.

b

---

<div class="post-metadata">

**Author:** ![luma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d6d6ee/32.png) [@luma](https://www.ruby-forum.com/u/luma)\
**Post date:** [March 28, 2007, 7:33pm UTC](https://www.ruby-forum.com/t/creating-xml-files-on-the-hard-disk/90346/3 "2007-03-28T19:33:00Z")

</div>

Hi,

On Mar 27, 7:42 pm, “Luma” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’ve written a rxml template. What must I write in my rails-controller  
> to get xml files out of this - not displayed on the screen, but just  
> saved on the hard disk? And where do I have to store the rxml file?

Actually, you could be doing it without using caching…

class LaboratoryNotebookController \< ApplicationController

def index  
render :action =\> ‘index.rxml’

```
fp = File.open RAILS_ROOT+"/myfile.xml", 'w+'
fp.write @response.body
fp.close

```

end

end

remember that XHTML is actually XML too, therefore, the rxml extension  
or the rhtml extension is not really important…

---

<div class="post-metadata">

**Author:** ![luma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d6d6ee/32.png) [@luma](https://www.ruby-forum.com/u/luma)\
**Post date:** [March 28, 2007, 7:53pm UTC](https://www.ruby-forum.com/t/creating-xml-files-on-the-hard-disk/90346/4 "2007-03-28T19:53:05Z")

</div>

This is a good idea. Now I tried to simulate a post request for the  
action “create\_xml” like this:

xhr :post, :create\_xml, :order =\> @order

But rails doesn’t know the “xhr”. Do I need to include  
“ActionController::TestProcess”, and what is the syntax?

undefined method `xhr’ for #BestellContrController:0x4660374  
RAILS\_ROOT: ./script/…/config/…

Application Trace | Framework Trace | Full Trace  
#{RAILS\_ROOT}/app/controllers/bestell\_contr\_controller.rb:19:in  
`save\_order’

Thanks for help.

---

<div class="post-metadata">

**Author:** ![luma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d6d6ee/32.png) [@luma](https://www.ruby-forum.com/u/luma)\
**Post date:** [March 28, 2007, 10:23pm UTC](https://www.ruby-forum.com/t/creating-xml-files-on-the-hard-disk/90346/5 "2007-03-28T22:23:33Z")

</div>

It works. Thanks to both of you!
