Ruby Building Web Apps with Sinatra ERB Templates URL Parameters

Dan Maliano
Dan Maliano
11,151 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

Eric Butler
Eric Butler
31,915 Points
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
11,151 Points

Thank you very much Eric ;)