JJ Beck
JJ Beck

Reputation: 5283

Writing new file via controller

In the Rails controller, I'd like to write create a new file at public/my_file.txt and write the string This file is my_file.txt into the file. How can I do that?

Upvotes: 3

Views: 768

Answers (1)

sylv3rblade
sylv3rblade

Reputation: 621

File.open([full path to your file], 'w') { |file| file.write("your text") }

More info via ruby's file class

Upvotes: 4

Related Questions