Book Image

Learning Sinatra

By : Sudeep Agarwal, Manoj Sehrawat
Book Image

Learning Sinatra

By: Sudeep Agarwal, Manoj Sehrawat

Overview of this book

<p>Sinatra is a Ruby framework that is widely used in the Industry. You can use it to make a single-page web app or a large-scale one. With the increased online footprint, you can create and deploy your own application.</p> <p>Whether you are brand-new to online learning or a seasoned expert, this book will provide you with the skills you need to successfully create, customize, and deploy a Sinatra application. Starting from the beginning, this book will cover how to install Ruby and Sinatra, construct the back-end, design and customize the front-end layout, and utilize the innovative and user-friendly features of ORMs. By sequentially working through the steps in each chapter, you will quickly master Sinatra's features to create your own application.</p> <p>With ample screenshots and code that offers a play-by-play account of how to build an application, Learning Sinatra will ensure your success with this cutting-edge framework.</p>
Table of Contents (17 chapters)
Learning Sinatra
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Sending the data and designing the views


We can divide the routes based on the type of HTTP requests that they handle (GET and POST). For all the GET requests, we might fetch some data from the backend and show an HTML page, and for all the POST requests, we will call a model method and return to the same HTML page. So, for now, we will just write the code to call an HTML page and design the actual pages later on.

To design the pages, we will use a templating engine called HAML. HAML is a ruby gem that makes it easier to write HTML codes. To make sure that our application doesn't throw any errors, we will install the HAML gem now and create empty files.

To install the gem, we will add it to the Gemfile and run bundle install. Add the following line to the Gemfile and run bundle install:

gem 'haml', '4.0.6'

This will install the HAML gem.

Let's now add code to each of the routes and methods to the model wherever required. We will start in the order in which we have defined the routes.

Showing a...