I am passing the contents of a textarea in my rails view to the server by a POST call. How can I store the contents as a separate file, say contents_userId.txt on my server and at the same time store my file in database allowing me to access the various files a single user has...or for any other purpose.
A:
Hi there,
Not sure why you would wish to save the input to a file and to the database, but anyways... here is a link that will show you the methods you need and some example code:
http://www.tutorialspoint.com/ruby/ruby_input_output.htm
Or, skipping to the examples:
aFile = File.new("filename", "mode")
# ... process the file
aFile.close
... or ...
File.open("filename", "mode") do |aFile|
# ... process the file
end
See the link for more details, valid mode strings, etc.
Scott S.
2010-07-31 04:15:56