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 trialbagi
9,405 PointsIn the get route for the "/greet/:name" path, respond with a string reading "Hello" followed by the contents of the name
In the get route for the "/greet/:name" path, respond with a string reading "Hello" followed by the contents of the name URL parameter.
Please, help me to solve these Challenge Task.
require "sinatra"
def hello(name)
puts "Hello" # string.read('Hello')
rescue Errno:ENOENT
return nil
end
get "/greet/:name" do
hello(params[:name])
end
1 Answer
William Li
Courses Plus Student 26,868 PointsYou only need to combine the String "Hello " and the contents of the name URL parameter in the get route body here.
hello
method isn't needed for this challenge. Sometimes we write helper function if it helps to reduce the program's complexity, but for a simple problem like this one, helper function is overkill and only makes code more complicated than it needs to be.
require "sinatra"
get "/greet/:name" do
# YOUR CODE HERE
"Hello " + params[:name]
end
Hope it helps.
bagi
9,405 Pointsbagi
9,405 PointsThank you so much)