creating xml files on the hard disk

0 views
Skip to first unread message

Luma

unread,
Mar 27, 2007, 7:42:29 PM3/27/07
to Ruby on Rails: Talk
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?

Ben Munat

unread,
Mar 28, 2007, 12:15:01 AM3/28/07
to rubyonra...@googlegroups.com
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

Sébastien Boisvert (sebhtml)

unread,
Mar 28, 2007, 1:30:59 PM3/28/07
to Ruby on Rails: Talk
Hi,

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

Luma

unread,
Mar 28, 2007, 1:40:53 PM3/28/07
to Ruby on Rails: Talk
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.

Luma

unread,
Mar 28, 2007, 4:22:35 PM3/28/07
to Ruby on Rails: Talk
It works. Thanks to both of you!

Reply all
Reply to author
Forward
0 new messages