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 trial

Ruby Building Web Apps with Sinatra ERB Templates URL Parameters

Christopher Kemp
Christopher Kemp
3,446 Points

get "/greet/:name"

I'm really not sure where I'm going wrong here. I went back to the lecture and I thought I followed the same process as Jay, but it just keeps saying Bummer: Try again!

Which it's not helpful in these projects to be unable to look at where the code crashes.

hello.rb
require "sinatra"

get "/greet/:name" do
  "hello" 
  page_content(params[:name])
end

1 Answer

Jay McGavren
STAFF
Jay McGavren
Treehouse Teacher

You are right that "Try again" is not the most helpful error message. Unfortunately when the code doesn't run successfully, that's all that gets produced.

The issue is that you're calling a page_content method that doesn't exist. page_content is available in the wiki app only because we define it there - it's not part of Sinatra. This challenge example is a completely separate app, and so any attempt to call page_content will fail (unless you define a method named page_content yourself).

But that's not what you want to do anyway. You just need the content of the :name URL parameter, which is available as part of the params hash:

require "sinatra"

get "/greet/:name" do
  "hello #{params[:name]}"
end
Christopher Kemp
Christopher Kemp
3,446 Points

Thank you! I eventually was able to find an answer that worked through the internet, but I wasn't really sure why it worked. This was extremely helpful for my understanding! I have really enjoyed this course because of how much it challenges my understanding of Ruby. I have taken courses before that really all you do is follow along with someone that is writing code, but you never learn what it means or does to the core. So far you guys have delivered on getting me to understand what each snipit of code is used for, how it works, and the course has really helped me to solidify my understanding of Ruby!