O'Reilly logo

Learning Sinatra by Manoj Sehrawat, Sudeep Agarwal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

What did the code do?

You might have already guessed how this code works. We have added a new require line to helloworld.rb. This loads the haml gem. In the controller, we are returning a haml instead of a string.

Let's see line 5 once again:

5   haml :index

This is a ruby method call. The haml method has argument:index. The method will look for a file named index.haml in the views folder, generate the HTML from HAML, and return it to the client.

The following method will call the required file:

haml :<filename>

If the file does not exist in the views folder or if there are any syntax errors in HAML, then the application will throw an error.

Let's now see index.haml:

1 %body
2   %h1
3     Hello World!

We will see later that an HTML element can be defined by

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required