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 Getting HTML from a Template

Ernesto Ramos
Ernesto Ramos
4,440 Points

:welcome

How does Ruby know to call the HTML code from :welcome?

2 Answers

Mohamed Fouda
PLUS
Mohamed Fouda
Courses Plus Student 6,202 Points

Thatโ€™s Sinatra job as sinatra is a pre coded ruby code dose this job for you and sinatra prepared to look at ERB templates by default in directory called views you should pit you erb files inside view

And when you go in your ruby main code and call that erb template Like in video erb :welcome Means go and pick template called welcome from views folder and render it in HTML As i said that is Sinatraโ€™s job

Mohamed Fouda
Mohamed Fouda
Courses Plus Student 6,202 Points

For more information check sinatra documentation

Lian Maung
Lian Maung
4,611 Points

I have a LoadError. Being wiki.rb and welcome.erb files inside 'views' folder, when I run 'ruby wiki.rb' in the console, it gives be this error "ruby: No such file or directory -- wiki.rb (LoadError)". What could I be missing here?

wiki.rb should not be in the views folder. wiki.rb and the views folder should be in a folder, and the views folder should contain welcome.erb.

When you run ruby wiki.rb, you are indicating that wiki.rb is in the same folder as the console is pointing to. If it's in a different folder, you need to include a path to the file, such as ruby views\wiki.rb or ruby views/wiki.rb, depending on your operating system. Sinatra would then start, and expect welcome.erb to be in a folder named views inside the folder named views.