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 trialsilva celso
13,513 PointsThe route block should take the request parameter named "string", call the reverse method on it, and return the result.
I'm a bit confused about this question Any help will be much appreciated,
require "sinatra"
get "/input" do
erb :input
end
post "/reverse" do
end
<form method="post" action="/reverse" >
<fieldset>
<label for="info">Info</label>
<input type="text" id="info" name="string">
</fieldset>
<input type="submit">
<form>
1 Answer
Jay McGavren
Treehouse TeacherFrom Task 2:
The route block should take the request parameter named "string", call the reverse method on it, and return the result.
post "/reverse" do
# Your code goes here!
# Whatever the last expression within this block is,
# that will be the block's return value,
# and that's what the browser will display.
# Like this:
"This will be the block return value, which the browser will display."
end
Now, of course, you don't want the block to return "This will be the block return value, which the browser will display."
, you want it to return the reversed "string"
parameter.
You can access that parameter like this:
params["string"]
params["string"]
will return the string that was submitted from the form. Every Ruby string has a reverse
method you can call on it, which returns the same string, but backwards:
puts "hello".reverse # prints "olleh"
Call reverse on the string returned from params["string"]
, and return the result from your Sinatra route block, and you should pass the challenge!