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 trialOsvaldo Gonzalez
5,340 PointsBack in hello.rb, at the end of the route block, render the views/hello.erb template. What am I doing wrong?
Please Help
require "sinatra"
set :bind, "0.0.0.0"
def page_content(title)
File.read("pages/#{title}.txt")
rescue Errno::ENOENT
return nil
end
get "/greet/:name" do
@name = params[:name]
@content = content_page(@name)
erb :show
require 'views/hello.erb'
get '/' do
erb :views/hello
end
<p>Hello <%= @name %></p>
2 Answers
Joan Estep
10,739 PointsThis confused me too, but I found that this completed the challenge:
erb :hello
Jay McGavren
Treehouse TeacherYou may have misunderstood how the code is supposed to work, here. The goal is to let the user visit a path like /greet/Osvaldo
or /greet/Jay
, take the second portion of the path (Osvaldo
or Jay
), and display a greeting based only on that path (<p>Hello Osvaldo</p>
or <p>Hello Jay</p>
).
So this code you have is a good use of URL parameters. This is all you need to do to retrieve the name, you don't need to define or call a page_content
method.
get "/greet/:name" do
@name = params[:name]
But you need to add an end
keyword to close the route's block. Also, get "/greet/:name"
is the only route you need; you don't need a get '/'
route.
I would recommend going back and reviewing the video on ERB templates. The info you need to render the template should be there.