Q:

Rails creating local xml file

I need to create a local xml file from a rails application and then copy it to a location on another server.
I have tried  using the File.new option to create a new file but it gives me an error saying the file does not exist. After looking closer at the documentation it says that File.new opens a file that already exists.
I can't see any way to create a local file using Ruby, what am I missing?

A:

Assuming you have built up your XML into a string, xml_string, you can do:
xml_file = open(filename, 'w')
xml_file.write xml_string
xml_file.close

Or using the block syntax to achieve this in one line:
File.open(local_filename, 'w') { |f| f.write(xml_string) }

