Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialPRAKASH ANAND
Courses Plus Student 5,060 PointsWe 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.
require "sinatra"
get "/input" do
erb :input
end
post "/reverse" do
reverse()
end
<form method="post" action="/reverse">
<input type="text" name="string">
<input type="submit">
</form>
1 Answer
Thomas Wright
4,532 PointsYou'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
.