What I Learned Working On My Sinatra Project.

Josh burger
4 min readFeb 26, 2021

Hello everyone, Here I am again at the end of phase 2 and I just finished my second project using Sinatra. I was honestly really excited coming into this phase of the software engineering program because I was going to learn how to visually see what I am creating and it made me feel like an ENGINEER!

When I started this project, I decided to go with a calorie tracker that will allow my user to be able to keep track of their intakes throwout the day on a particular day. The calorie tracker also keeps track of everyone’s intakes and you have the access to see their profile with the intakes they have. A few pictures below!

Account page
All users intakes

As you can see from the pictures above the intake records a date, name, amount of calories. The user also can use the CRUD I learned during the project. They can C- Create a new intake, R-Read a new intake, U-Update an intake, and the last D- Delete an intake. A user also has a navbar to navigate around the website. Below I will run you through a little on the overview of what I learned working on the project.

Starting with the database I had to make 2 tables, One table for users and the second table for intakes. Picture of schema below!

database schema

With the tables I created, I went ahead and created 2 models to add my associations to a User and Intake, also validate the email and secure password. After I had my associations linked up through active record i was able to start working with my controllers, models and, views. This is where things got fun! Here is a little info on what a controller, model, the view is:

  1. Controller- Provide the main interface and application logic.
  2. Model- Provide an object-oriented abstraction or metaphor for the data in our application. Our models do the job of interacting with the database by asking for certain data and using that data to create a new instance of our class. we can then interact with that data by using the methods and properties of the instance of that class.
  3. View- Present information to the user. Any code that is responsible for presenting data or output to the user, from methods that use a bunch of puts, to HTML, to ERB templates, could be considered a View. in web applications, views are generally represented by ERB templates that generate HTML.

Here is an example of the intake controller i used within my project:

Intake controller

Here is an example of the Model i used within my project:

Intake Model

Here is an example of a View I used within my project:

With all of this combined, I can route my website how I would like and be able to put whatever logic i want within the controller to display on the views to the user. This is how I can assign an intake to a user because in my associations a intake belongs to a user while a user has many intakes. I learned a lot going about this project and I am very pleased with how it turned out. I plan on putting more work into the site and growing it. Thank you for reading my blog and I hope you enjoyed my experience of learning Sinatra.

--

--