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

Sinatra application layout

As Sinatra can be used for applications that can be bare minimum or large and complex, the application structure can grow bigger with the need.

For now, let's stick to the basic layout.

A basic Sinatra application will have a ruby file that has all the controllers defined (for example, helloworld.rb).

If we want to have different HTML files (or different views), we should place all such files in the views folder.

The layout is as follows:

helloworld.rb
views/

Naming convention: The main application file is generally named app.rb or website.rb.

Let's now see how to write views. Views can be written in HTML. However, there are some gems in Ruby that make our lives easier. One of them is HAML.

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