标签: ruby-on-rails
在Rails控制器中,我想写public/my_file.txt创建一个新文件并将字符串This file is my_file.txt写入文件。我怎么能这样做?
public/my_file.txt
This file is my_file.txt
答案 0 :(得分:4)
File.open([full path to your file], 'w') { |file| file.write("your text") }
更多信息来自ruby的file课程