开发者

Save the contents of a textarea into a text file with Ruby

开发者 https://www.devze.com 2022-12-19 22:26 出处:网络
In a little Sinatra app I\'m working on, I want to store what I write in a textarea into a text file. What\'s the simplest开发者_JAVA百科 way to do this?In your post handler (you have it, right?) just

In a little Sinatra app I'm working on, I want to store what I write in a textarea into a text file. What's the simplest开发者_JAVA百科 way to do this?


In your post handler (you have it, right?) just dump whatever has been passed through your form field into a file:

post '/' do
  File.open('name_of_the_file.txt', 'w') do |f|
    f.write params[:name_of_your_textarea]
  end
end
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号