Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Practice Sinatra Basics HTML Forms HTML Forms

We tried a POST request to the /reverse path, but we got a bad response.

We tried a POST request to the /reverse path, but we got a bad response.

app.rb
require "sinatra"
get "/input" do

  erb :input
end
post "/reverse" do
  reverse()


end
views/input.erb
<form method="post" action="/reverse">
  <input type="text" name="string">
  <input type="submit">


</form>

1 Answer

You'll need to do a little more work here to send the form's data to the POST request. In this case, you'll need to use something like params["string"].reverse. In Sinatra, Params returns a hash. By giving your text input a name, you've created a key in that hash with the same name. The value of that key is the value that was entered in the form. So to access that value you'll look at the "string" key in the params hash using params["string"]. From there, you can reverse the string using the Ruby method .reverse.