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!

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 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,148 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