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 trial

Ruby Building Web Apps with Sinatra ERB Templates URL Parameters

Dan Maliano
Dan Maliano
12,142 Points

respond with a string reading "Hello" followed by the contents of the name URL parameter.

What am I doing wrong here?

hello.rb
require "sinatra"

get "/greet/:name" do
    puts "Hello #{params[:name]}"

end

1 Answer

require "sinatra"

get "/greet/:name" do
  "Hello" + params[:name]
end

Yours isn't quite right because you're using puts instead of return (or omitting both because Ruby implicitly "returns" whatever the last thing in a function is, as shown in my answer). Still, I think the answer-evaluator might be too finicky, because you should be able to do string interpolation like you did ("Hello #{params[:name]}") but when I did it it said it was wrong. I dunno.

Dan Maliano
Dan Maliano
12,142 Points

Thank you very much Eric ;)