views:

21

answers:

1

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?

+1  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) }
mikej
I was just trying a file.open with 'w'. It gives me a permission denied, so I suppose it is trying to do the right thing.
inKit
Are you getting the permission denied on your local development server or on a remote hosting server? Sounds like the web server user doesn't have permission to write to the location you're trying to use. If the intention is to write the file to disk that it can be copied elsewhere then you probably just need a directory you can use for storing the temporary copies of the files prior to transfer.
mikej
Its on the local development server that the permission denied is occurring. I'll have my team mate set up the permissions when he gets in.
inKit