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

Writing routes for the responsibilities of the application


So our next step will be defining the valid routes for our application. Let's discuss the responsibilities of our application:

  • Showing a page for all the existing lists

  • Showing a page to create a new list

  • Saving a new list

  • Deleting a list

  • Showing a page to edit a list

  • Updating a list

  • Changing permissions on a list

Let's write the routes for each of these responsibilities in the following sections.

Showing a page for all the existing lists

This will load all the available lists from the database and a page that will show them. The route is defined by setting the URL path and defining the processing code. For example, in http://www.example.com/test/, the URL path is '/test/'; similarly, in http://www.example.com, the URL path is '/'. The trailing '/' is optional and so we need to handle this in our routes.

Now, we continue writing in app.rb:

     1	require 'sinatra'
     2	require 'sequel'
     3
     4	class Todo < Sinatra::Application
  ...