Ruby Building Web Apps with Sinatra ERB Templates URL Parameters

In 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.

hello.rb
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
PRO
William Li
Pro Student 26,793 Points

You 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.

Thank you so much)