Creating a server side text file for a Ruby on Rails form

I use Ruby on Rails and have a form that receives information from user input. Then I want to take user input and write it to a server side text file. I hope to save the file somewhere, for example /public/UserInput.txt.

Is there a way to use Ruby on Rails for this? Or do I need another language for this, like PHP? Anyway, can someone give me an example of how to do this?

Thanks in advance.

Update The code I'm trying to do does not give me a text file:

after_save :create_file def create_file parameter_file = File.new('C:\\parameter_file.txt', "w") parameter_file.puts(:parameter) end 
+7
ruby ruby-on-rails webforms server-side text-files
source share
1 answer

This is not a problem with specific rails. It can be used in a regular ruby.

 path = "/some/file/path.txt" content = "data from the form" File.open(path, "w+") do |f| f.write(content) end 

where target is where you want the file to be, and content is any data you extract from the form.

+15
source share

All Articles