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 trialRobert Jenkins
4,146 PointsHow do I respond with a string reading "Hello" followed by the contents of the name URL params?
In the get route for the "/greet/:name" path, respond with a string reading "Hello" followed by the contents of the name URL parameter.
require "sinatra"
get "/greet/:name" do
"Hello" params[:name]
end
2 Answers
scribbles
21,173 PointsYou can use string interpolation to add params[:name] into the string. it would work like this:
require "sinatra"
get "/greet/:name" do
"Hello #{params[:name]}"
end
Or you could just concatenate params[:name] onto the end of the string:
require "sinatra"
get "/greet/:name" do
"Hello " + params[:name]
end
Peter Eriksson
12,187 PointsHow does params work here?
Thx