Creating xml files on the hard disk

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?

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

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

b

Hi,

On Mar 27, 7:42 pm, “Luma” [email protected] 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…

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.

It works. Thanks to both of you!