tags:

views:

108

answers:

1

Hey,

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 way to do this?

A: 

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
Mladen Jablanović
I did *exactly* that, but when I try it on the localhost, it gives me a 404, which is completely insane!
Joel M.
You should check whether the path of the page you are submitting the form to matches the handler path.
Mladen Jablanović
it does. I even rewrote it to double check.
Joel M.
How do you start Sinatra and are you pointing your browser to the right port?
Mladen Jablanović