Author: admin

  • Database Setup for the Sinatra App

    The database setup for our Sinatra app consists of the following: Here’s the database config file: yaml And the ORM and database adaptor gems in the Gemfile: ruby And here’s how you register the ORM and database config in app.rb. ruby

  • The Main File (app.rb)

    app.rb is the main entry point into our app where we define what the app does. Notice how we’ve subclassed Sinatra::Base to make the app modular. As you can see below, we include some settings for fetching folders as well as defining the public folder (for storing static files). Another important note here is that we register the Sinatra::ActiveRecordExtension which…

  • Structuring Our Ruby App

    To begin with, we’ll take the modular approach with this build so it’s easy to organize functionality in a clean and intuitive way. Our cost-of-living calculator app needs: The app will fetch cost-of-living data from an API hosted on RapidAPI. We won’t include any tests or user authentication to keep this tutorial brief. Go ahead…

  • Regular (Classical) Vs. Modular Sinatra Apps

    When it comes to structure in Sinatra apps, you can have regular — sometimes referred to as “classical” — apps, or “modular” ones. In a classical Sinatra app, all your code lives in one file. You’ll almost always find that you can only run one Sinatra app per Ruby process if you choose the regular…

  • Our Example Ruby App

    The app we are building will let you input how much you earn as well as the city and country you’d like to move to. Then it will output a few living expense figures for that city. Prerequisites To follow along, ensure you have the following: You can also get the full code for the example…

  • What Is Sinatra Good For?

    Because of its lightweight and Rack-based architecture, Sinatra is great for building APIs, mountable app engines, command-line tools, and simple apps like the one we’ll build in this tutorial.

  • Overview of Sinatra

    Compared to Ruby on Rails, a full-stack web framework, Sinatra is a very lean micro-framework originally developed by Blake Mizerany to help Ruby developers build applications with “minimal effort”. With Sinatra, there is no Model-View-Controller (MVC) pattern, nor does it encourage you to use “convention over configuration” principles. Instead, you get a flexible tool to build simple,…

  • Ruby on Rails AJAX

    AJAX Introduction AJAX stands for Asynchronous Javascript and XML. It is a mixture of several technologies and is an important part of Rails application. It allows client side changes without reloading the page. Let us see the working of a normal web server. On typing a web address and clicking on search, the browser makes…

  • Rails Validation

    Rails validation defines valid states for each of your Active Record model classes. They are used to ensure that only valid details are entered into your database. Rails make it easy to add validations to your model classes and allows you to create your own validation methods as well. Using built-in validation DSL, you can…

  • Testing in Rails

    Rails test is very simple to write and run for your application. As Rails script generates models and controllers, in the same way test files are also generated. Rails also uses a separate database for testing. Test database in an application is rebuilt each time the application’s test run, and hence you always have a…