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

The 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,

app.rb
require "sinatra"

get "/input" do  
  erb :input
end 

post "/reverse" do 

end 
views/input.erb
<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
STAFF
Jay McGavren
Treehouse Teacher

From 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!