Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Building Web Apps with Sinatra ERB Templates Loading ERB Templates

Kyle Shamblin
Kyle Shamblin
9,945 Points

What am I doing wrong? Bug?

Am I making a syntax error or is this a bug? Thanks in advance.

require "sinatra"

get "/hello" do
  erb: welcome.erb
<h1>Welcome to our app!</h1>

2 Answers

Kevin Korte
Kevin Korte
28,109 Points

I'm not really familiar with sinatra, but your code looks like it doesn't match the example code in the docs. They have

get '/' do
  erb :index

Which, you have your colon in the wrong spot. Try fixing that and let us know how it works

Kyle Shamblin
Kyle Shamblin
9,945 Points

Thanks Kevin! the colon was my problem. Also, to anyone else who might be confused too: You dont need .erb at the end when you call erb :erb_file

Jacob Herrington
Jacob Herrington
15,835 Points

Hey Kyle Shamblin,

Just for future reference, in Ruby the colon sigil denotes a symbol. You can read more about symbols in this blog post from 2005.

For a easy to swallow example:

# strings "foo" & "foo" are not the same object
"foo".equal? "foo"  # false

# symbols :foo & :foo are the same object
:foo.equal? :foo    # true

If you understand the symbol you will understand that erb :welcome is just a symbol (:welcome) being passed to a method (erb).

Also, note that Ruby doesn't require parentheses when passing a single argument to a method. Jay McGavren has decided to write the code without the parentheses. If it helps you remember the syntax, you can also write it like this:

# get and erb are methods, you can pass a single argument with or without parentheses
get("/hello") do